Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving build.dart #403

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading