Skip to content

Commit

Permalink
Improving build.dart (#403)
Browse files Browse the repository at this point in the history
* fix

* ci
  • Loading branch information
robertbastian committed Jan 10, 2024
1 parent f19bb8a commit 600ad7d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
- name: Install Dart
uses: dart-lang/setup-dart@v1
with:
sdk: 3.3.0-277.0.dev
sdk: 3.3.0-279.1.beta

# Cargo-make boilerplate
- name: Get cargo-make version
Expand Down
20 changes: 11 additions & 9 deletions example/dart/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@ import 'package:native_assets_cli/native_assets_cli.dart';
import 'dart:io';

const crateName = 'diplomat-example';
const release = false;
const assetId = 'package:example/src/lib.g.dart';

void main(List<String> args) async {
final config = await BuildConfig.fromArgs(args);

await Process.run('cargo', [
final cargo = await Process.run('cargo', [
'rustc',
'-p',
crateName,
'--crate-type=cdylib',
if (release) '--release'
], environment: {
'CARGO_TARGET_DIR': config.outDir.path
});
]);

if (cargo.exitCode != 0) {
throw cargo.stderr;
}

final libPath =
'${config.outDir.path}/${release ? 'release' : 'debug'}/lib${crateName.replaceAll("-", "_")}.${Platform.isMacOS ? 'dylib' : Platform.isWindows ? 'dll' : 'so'}';
'../../target/debug/${Target.current.os.dylibFileName(crateName.replaceAll('-', '_'))}';

await File(libPath).copy('${config.outDir.path}/lib');

await BuildOutput(
assets: [
Asset(
id: assetId,
linkMode: LinkMode.static,
target: Target.current,
path: AssetAbsolutePath(Uri.file(libPath)))
path: AssetAbsolutePath(Uri.file('${config.outDir.path}/lib')))
],
dependencies: Dependencies([Uri.file('build.dart')]),
dependencies: Dependencies([Uri.file('build.dart'), Uri.file(libPath)]),
).writeToFile(outDir: config.outDir);
}
2 changes: 1 addition & 1 deletion example/dart/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,4 @@ packages:
source: hosted
version: "2.1.1"
sdks:
dart: "3.3.0-277.0.dev"
dart: ">=3.3.0-279.1.beta <4.0.0"
2 changes: 1 addition & 1 deletion example/dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: example
version: 0.0.0

environment:
sdk: 3.3.0-277.0.dev
sdk: ^3.3.0-279.1.beta

dependencies:
ffi: ^2.0.0
Expand Down
20 changes: 11 additions & 9 deletions feature_tests/dart/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@ import 'package:native_assets_cli/native_assets_cli.dart';
import 'dart:io';

const crateName = 'diplomat-feature-tests';
const release = false;
const assetId = 'package:feature_tests/src/lib.g.dart';

void main(List<String> args) async {
final config = await BuildConfig.fromArgs(args);

await Process.run('cargo', [
final cargo = await Process.run('cargo', [
'rustc',
'-p',
crateName,
'--crate-type=cdylib',
if (release) '--release'
], environment: {
'CARGO_TARGET_DIR': config.outDir.path
});
]);

if (cargo.exitCode != 0) {
throw cargo.stderr;
}

final libPath =
'${config.outDir.path}/${release ? 'release' : 'debug'}/lib${crateName.replaceAll("-", "_")}.${Platform.isMacOS ? 'dylib' : Platform.isWindows ? 'dll' : 'so'}';
'../../target/debug/${Target.current.os.dylibFileName(crateName.replaceAll('-', '_'))}';

await File(libPath).copy('${config.outDir.path}/lib');

await BuildOutput(
assets: [
Asset(
id: assetId,
linkMode: LinkMode.static,
target: Target.current,
path: AssetAbsolutePath(Uri.file(libPath)))
path: AssetAbsolutePath(Uri.file('${config.outDir.path}/lib')))
],
dependencies: Dependencies([Uri.file('build.dart')]),
dependencies: Dependencies([Uri.file('build.dart'), Uri.file(libPath)]),
).writeToFile(outDir: config.outDir);
}
2 changes: 1 addition & 1 deletion feature_tests/dart/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,4 @@ packages:
source: hosted
version: "2.1.1"
sdks:
dart: "3.3.0-277.0.dev"
dart: ">=3.3.0-279.1.beta <4.0.0"
2 changes: 1 addition & 1 deletion feature_tests/dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: feature_tests
version: 0.0.0

environment:
sdk: 3.3.0-277.0.dev
sdk: ^3.3.0-279.1.beta

dependencies:
ffi: ^2.0.0
Expand Down

0 comments on commit 600ad7d

Please sign in to comment.