Skip to content

Commit

Permalink
feat: added extraCargoArgs argument to RustBuilder (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored Aug 14, 2024
1 parent 7b3c533 commit 889b61a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/flutter_package/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void main(List<String> args) async {
package: 'flutter_package',
cratePath: 'rust',
buildConfig: buildConfig,
extraCargoArgs: ['--features=sum'],
);
await builder.run(output: output);
});
Expand Down
3 changes: 3 additions & 0 deletions example/flutter_package/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2021"
[lib]
crate-type = ["cdylib"]

[features]
sum=[]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
5 changes: 2 additions & 3 deletions example/flutter_package/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::usize;

#[cfg(feature = "sum")]
#[no_mangle]
pub extern "C" fn sum(a: usize, b: usize) -> usize {
println!("Hello from rust {a} + {b}");
a + b
}

#[cfg(test)]
#[cfg(all(test, feature = "sum"))]
mod tests {
use super::*;

Expand Down
5 changes: 5 additions & 0 deletions native_toolchain_rust/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class RustBuilder {
this.toolchain,
required this.cratePath,
required this.buildConfig,
this.extraCargoArgs = const [],
this.release = true,
this.assetName,
this.useNativeManifest = true,
Expand Down Expand Up @@ -140,6 +141,9 @@ class RustBuilder {
/// dependencies. Default value adds `hook/build.dart` as dependency.
final List<String> dartBuildFiles;

/// Extra arguments to pass to `cargo build`.
final List<String> extraCargoArgs;

/// Whether to build in release mode. Default is `true` even for debug builds.
final bool release;

Expand Down Expand Up @@ -209,6 +213,7 @@ class RustBuilder {
target.triple,
'--target-dir',
outDir.toFilePath(),
...extraCargoArgs,
],
environment: await _buildEnvironment(
outDir,
Expand Down

0 comments on commit 889b61a

Please sign in to comment.