Skip to content

Commit 4536e70

Browse files
Bump native_assets_cli from 0.11.0 to 0.12.0 (#15)
* Bump native_assets_cli from 0.11.0 to 0.12.0 Bumps [native_assets_cli](https://github.com/dart-lang/native/tree/main/pkgs) from 0.11.0 to 0.12.0. - [Release notes](https://github.com/dart-lang/native/releases) - [Commits](https://github.com/dart-lang/native/commits/native_assets_cli-v0.12.0/pkgs) --- updated-dependencies: - dependency-name: native_assets_cli dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * bump native_assets_cli and nativa_assets_builder to 0.12.0, remove extra added env vars for windows, fix tests * bump native_assets_cli to 0.12.0 for example/add --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: rainyl <[email protected]>
1 parent 7177374 commit 4536e70

12 files changed

+135
-63
lines changed

example/add/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
native_toolchain_cmake:
1313
path: ../..
1414
logging: ^1.3.0
15-
native_assets_cli: ^0.11.0
15+
native_assets_cli: ^0.12.0
1616

1717
dev_dependencies:
1818
lints: ^5.0.0

example/example.dart

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// ignore_for_file: dead_code
2+
import 'dart:io';
3+
4+
import 'package:logging/logging.dart';
5+
import 'package:native_assets_cli/code_assets_builder.dart';
6+
import 'package:native_assets_cli/native_assets_cli.dart';
7+
import 'package:native_toolchain_cmake/native_toolchain_cmake.dart';
8+
9+
void main(List<String> args) async {
10+
await build(args, (input, output) async {
11+
final sourceDir = Directory(await getPackagePath('add')).uri.resolve('src');
12+
const exampleGit = false;
13+
if (!exampleGit) {
14+
await runBuild(input, output, sourceDir);
15+
} else {
16+
await runBuildGit(input, output, sourceDir);
17+
}
18+
});
19+
}
20+
21+
const name = 'add';
22+
23+
Future<void> runBuild(
24+
BuildInput input,
25+
BuildOutputBuilder output,
26+
Uri sourceDir,
27+
) async {
28+
final _logger = Logger('')
29+
..level = Level.ALL
30+
// temp fwd to stderr until process logs pass to stdout
31+
..onRecord.listen((record) => stderr.writeln(record));
32+
final builder = CMakeBuilder.create(
33+
name: name,
34+
sourceDir: sourceDir,
35+
defines: {
36+
'CMAKE_BUILD_TYPE': 'Release',
37+
'CMAKE_INSTALL_PREFIX': '${input.outputDirectory.toFilePath()}/install',
38+
},
39+
targets: [
40+
'install',
41+
],
42+
buildLocal: true,
43+
logger: _logger,
44+
);
45+
46+
await builder.run(input: input, output: output, logger: _logger);
47+
48+
final buildjson = input.config.json;
49+
_logger.info('Build output: $buildjson');
50+
51+
// automatically search and add libraries
52+
final outLibs = await output.findAndAddCodeAssets(
53+
input,
54+
names: {r'(lib)?add\.(dll|so|dylib)': 'add.dart'},
55+
outDir: input.outputDirectory.resolve('install'),
56+
logger: _logger,
57+
regExp: true,
58+
);
59+
60+
// Do something else with outLibs uris
61+
_logger.info('Found libs: $outLibs');
62+
}
63+
64+
Future<void> runBuildGit(
65+
BuildInput input,
66+
BuildOutputBuilder output,
67+
Uri sourceDir,
68+
) async {
69+
final logger = Logger('')
70+
..level = Level.ALL
71+
// temp fwd to stderr until process logs pass to stdout
72+
..onRecord.listen((record) => stderr.writeln(record));
73+
// From git url
74+
final builder = CMakeBuilder.fromGit(
75+
gitUrl: "https://github.com/rainyl/native_toolchain_cmake.git",
76+
sourceDir: sourceDir,
77+
name: name,
78+
gitSubDir: "example/add/src",
79+
defines: {
80+
'CMAKE_BUILD_TYPE': 'Release',
81+
'CMAKE_INSTALL_PREFIX': '${input.outputDirectory.toFilePath()}/install',
82+
},
83+
targets: ['install'],
84+
buildLocal: true,
85+
logger: logger,
86+
);
87+
88+
await builder.run(
89+
input: input,
90+
output: output,
91+
logger: logger,
92+
);
93+
94+
// manually add assets
95+
final libPath = switch (input.config.code.targetOS) {
96+
OS.linux => "install/lib/libadd.so",
97+
OS.macOS => "install/lib/libadd.dylib",
98+
OS.windows => "install/lib/add.dll",
99+
OS.android => "install/lib/libadd.so",
100+
OS.iOS => "install/lib/libadd.dylib",
101+
_ => throw UnsupportedError("Unsupported OS")
102+
};
103+
output.assets.code.add(
104+
CodeAsset(
105+
package: name,
106+
name: '$name.dart',
107+
linkMode: DynamicLoadingBundled(),
108+
os: input.config.code.targetOS,
109+
file: input.outputDirectory.resolve(libPath),
110+
architecture: input.config.code.targetArchitecture,
111+
),
112+
);
113+
}

lib/src/builder/builder.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,8 @@ class CMakeBuilder implements Builder {
221221
logLevel: logLevel,
222222
);
223223

224+
// Do not remove this line for potential extra variables in the future
224225
final Map<String, String> envVars = Map.from(Platform.environment);
225-
// TODO: patch environment variables for cmake
226-
// may be error if system drive is not C:
227-
// https://github.com/dart-lang/native/issues/2077
228-
if (input.config.code.targetOS == OS.windows) {
229-
envVars.addAll({
230-
"WINDIR": r"C:\WINDOWS",
231-
"SYSTEMDRIVE": "C:",
232-
});
233-
}
234226
await task.run(environment: envVars);
235227
}
236228
}

pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: native_toolchain_cmake
22
description: >-
3-
A library to invoke CMake for Dart Native Assets.
4-
version: 0.0.4
3+
A library to invoke and build CMake projects for Dart Native Assets.
4+
version: 0.0.5
55
repository: https://github.com/rainyl/native_toolchain_cmake
66

77
topics:
@@ -18,7 +18,8 @@ dependencies:
1818
glob: ^2.1.1
1919
logging: ^1.1.1
2020
meta: ^1.9.1
21-
native_assets_cli: ^0.11.0
21+
native_assets_cli: ">=0.12.0 <0.13.0"
22+
native_assets_builder: ">=0.12.0 <0.13.0" # required for CMake Env Vars
2223
path: ^1.9.1
2324
pub_semver: ^2.1.3
2425

test/builder/cmake_builder_cross_android_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ Future<Uri> buildLib(
111111
outputDirectory: tempUri,
112112
outputDirectoryShared: tempUriShared,
113113
)
114-
..config.setupBuild(
115-
linkingEnabled: false,
116-
dryRun: false,
117-
)
114+
..config.setupBuild(linkingEnabled: false)
118115
..config.setupShared(buildAssetTypes: [CodeAsset.type])
119116
..config.setupCode(
120117
targetOS: OS.android,

test/builder/cmake_builder_cross_ios_test.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ void main() {
5656
outputDirectory: tempUri,
5757
outputDirectoryShared: tempUri2,
5858
)
59-
..config.setupBuild(
60-
linkingEnabled: false,
61-
dryRun: false,
62-
)
59+
..config.setupBuild(linkingEnabled: false)
6360
..config.setupShared(buildAssetTypes: [CodeAsset.type])
6461
..config.setupCode(
6562
targetOS: OS.iOS,
@@ -178,10 +175,7 @@ Future<Uri> buildLib(
178175
outputDirectory: tempUri,
179176
outputDirectoryShared: tempUri2,
180177
)
181-
..config.setupBuild(
182-
linkingEnabled: false,
183-
dryRun: false,
184-
)
178+
..config.setupBuild(linkingEnabled: false)
185179
..config.setupShared(buildAssetTypes: [CodeAsset.type])
186180
..config.setupCode(
187181
targetOS: OS.iOS,

test/builder/cmake_builder_cross_linux_host_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ void main() {
3939
outputDirectory: tempUri,
4040
outputDirectoryShared: tempUri2,
4141
)
42-
..config.setupBuild(
43-
linkingEnabled: false,
44-
dryRun: false,
45-
)
42+
..config.setupBuild(linkingEnabled: false)
4643
..config.setupShared(buildAssetTypes: [CodeAsset.type])
4744
..config.setupCode(
4845
targetOS: OS.linux,

test/builder/cmake_builder_cross_macos_host_test.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ void main() {
4848
outputDirectory: tempUri,
4949
outputDirectoryShared: tempUri2,
5050
)
51-
..config.setupBuild(
52-
linkingEnabled: false,
53-
dryRun: false,
54-
)
51+
..config.setupBuild(linkingEnabled: false)
5552
..config.setupShared(buildAssetTypes: [CodeAsset.type])
5653
..config.setupCode(
5754
targetOS: OS.macOS,
@@ -132,10 +129,7 @@ Future<Uri> buildLib(
132129
outputDirectory: tempUri,
133130
outputDirectoryShared: tempUri2,
134131
)
135-
..config.setupBuild(
136-
linkingEnabled: false,
137-
dryRun: false,
138-
)
132+
..config.setupBuild(linkingEnabled: false)
139133
..config.setupShared(buildAssetTypes: [CodeAsset.type])
140134
..config.setupCode(
141135
targetOS: OS.macOS,

test/builder/cmake_builder_cross_windows_host_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ void main() async {
6262
outputDirectory: tempUri,
6363
outputDirectoryShared: tempUri2,
6464
)
65-
..config.setupBuild(
66-
linkingEnabled: false,
67-
dryRun: false,
68-
)
65+
..config.setupBuild(linkingEnabled: false)
6966
..config.setupShared(buildAssetTypes: [CodeAsset.type])
7067
..config.setupCode(
7168
targetOS: OS.windows,

test/builder/cmake_builder_git_test.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ void main() {
2222
gitUrl: 'https://github.com/rainyl/native_toolchain_cmake.git',
2323
sourceDir: tempDir,
2424
gitSubDir: subdir,
25-
logger: Logger('')
26-
..level = Level.ALL
27-
..onRecord.listen((record) => stderr.writeln(record)),
25+
logger: Logger('')..level = Level.ALL,
26+
// ..onRecord.listen((record) => stderr.writeln(record)),
2827
);
2928

3029
// The builder constructor creates a directory at sourceDir/external/<name>
@@ -66,10 +65,7 @@ void main() {
6665
outputDirectory: tempDir,
6766
outputDirectoryShared: tempDir,
6867
)
69-
..config.setupBuild(
70-
linkingEnabled: false,
71-
dryRun: false,
72-
)
68+
..config.setupBuild(linkingEnabled: false)
7369
..config.setupShared(
7470
buildAssetTypes: [CodeAsset.type],
7571
)

0 commit comments

Comments
 (0)