Skip to content

Commit

Permalink
feat! change crateManifestPath to cratePath (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored May 10, 2024
1 parent 998a178 commit 3f6c6e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion example/dart_package/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main(List<String> args) async {
await build(args, (BuildConfig buildConfig, BuildOutput output) async {
final builder = RustBuilder(
package: 'dart_package',
crateManifestPath: 'rust/Cargo.toml',
cratePath: 'rust',
buildConfig: buildConfig,
);
await builder.run(output: output);
Expand Down
2 changes: 1 addition & 1 deletion example/flutter_package/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main(List<String> args) async {
final builder = RustBuilder(
// The ID of native assets consists of package name and crate name.
package: 'flutter_package',
crateManifestPath: 'rust/Cargo.toml',
cratePath: 'rust',
buildConfig: buildConfig,
);
await builder.run(output: output);
Expand Down
2 changes: 1 addition & 1 deletion native_toolchain_rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main(List<String> args) async {
final builder = RustBuilder(
// The ID of native assets consists of package name and crate name.
package: '<your package name>',
crateManifestPath: 'rust/Cargo.toml',
cratePath: 'rust',
buildConfig: buildConfig,
);
await builder.run(output: output);
Expand Down
24 changes: 18 additions & 6 deletions native_toolchain_rust/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RustBuilder {
RustBuilder({
required this.package,
this.toolchain,
required this.crateManifestPath,
required this.cratePath,
required this.buildConfig,
this.useNativeManifest = true,
this.dartBuildFiles = const ['hook/build.dart'],
Expand All @@ -124,8 +124,8 @@ class RustBuilder {
/// ```
final String package;

/// Path to the `Cargo.toml` file relative to the package root.
final String crateManifestPath;
/// Path to the Rust crate directory relative to the package root.
final String cratePath;

/// Build config provided to the build callback from `native_assets_cli`.
final BuildConfig buildConfig;
Expand All @@ -148,9 +148,10 @@ class RustBuilder {
Future<void> run({required BuildOutput output}) async {
final toolchain = this.toolchain ?? await RustToolchain.withName('stable');

final manifestPath = buildConfig.packageRoot.resolve(
crateManifestPath,
);
final manifestPath = buildConfig.packageRoot
.resolve(cratePath)
.makeDirectory()
.resolve('Cargo.toml');
final manifestInfo = CrateManifestInfo.load(manifestPath);
final outDir =
buildConfig.outputDirectory.resolve('native_toolchain_rust/');
Expand Down Expand Up @@ -273,3 +274,14 @@ class RustBuilder {
}
}
}

extension on Uri {
// Ensure that the path ends with a `/`.
Uri makeDirectory() {
if (pathSegments.isNotEmpty && pathSegments.last.isNotEmpty) {
return replace(pathSegments: [...pathSegments, '']);
} else {
return this;
}
}
}

0 comments on commit 3f6c6e9

Please sign in to comment.