5
5
import 'dart:io' ;
6
6
7
7
import 'package:crypto/crypto.dart' show sha256;
8
- import 'package:intl4x/src/hook_helpers/build_options.dart' ;
9
- import 'package:intl4x/src/hook_helpers/hashes.dart' ;
10
- import 'package:intl4x/src/hook_helpers/shared.dart'
11
- show assetId, package, runProcess;
12
- import 'package:intl4x/src/hook_helpers/version.dart' ;
8
+ import 'package:intl4x/src/hook_helpers/build_libs.g.dart' show buildLib;
9
+ import 'package:intl4x/src/hook_helpers/build_options.dart'
10
+ show BuildModeEnum, getBuildOptions;
11
+ import 'package:intl4x/src/hook_helpers/hashes.dart' show fileHashes;
12
+ import 'package:intl4x/src/hook_helpers/shared.dart' show assetId, package;
13
+ import 'package:intl4x/src/hook_helpers/version.dart' show version;
13
14
import 'package:native_assets_cli/code_assets.dart' ;
14
- import 'package:path/path.dart' as path;
15
-
16
- const crateName = 'icu_capi' ;
17
15
18
16
void main (List <String > args) async {
19
17
await build (args, (input, output) async {
85
83
os: targetOS,
86
84
file: builtLibrary,
87
85
),
88
- linkInPackage: input.config.linkingEnabled ? package : null ,
86
+ routing:
87
+ input.config.linkingEnabled
88
+ ? const ToLinkHook (package)
89
+ : const ToAppBundle (),
89
90
);
90
91
91
92
output.addDependencies (buildMode.dependencies);
@@ -198,11 +199,27 @@ final class CheckoutMode extends BuildMode {
198
199
print ('Running in `checkout` mode' );
199
200
if (checkoutPath == null ) {
200
201
throw ArgumentError (
201
- 'Specify the ICU4X checkout folder'
202
- 'with the LOCAL_ICU4X_CHECKOUT variable ' ,
202
+ 'Specify the ICU4X checkout folder with the `checkoutPath` key in your '
203
+ 'pubspec build options. ' ,
203
204
);
204
205
}
205
- return await buildLib (input, checkoutPath! , treeshake);
206
+ final builtLib = await buildLib (
207
+ input.config.code.targetOS,
208
+ input.config.code.targetArchitecture,
209
+ input.config.buildStatic (treeshake),
210
+ input.config.code.targetOS == OS .iOS &&
211
+ input.config.code.iOS.targetSdk == IOSSdk .iPhoneSimulator,
212
+ Directory (checkoutPath! ),
213
+ [
214
+ 'icu_collator' ,
215
+ 'icu_datetime' ,
216
+ 'icu_list' ,
217
+ 'icu_decimal' ,
218
+ 'icu_plurals' ,
219
+ 'experimental_components' ,
220
+ ],
221
+ );
222
+ return builtLib.uri;
206
223
}
207
224
208
225
@override
@@ -211,127 +228,6 @@ final class CheckoutMode extends BuildMode {
211
228
];
212
229
}
213
230
214
- //TODO: Reuse code from package:icu4x as soon as it is published.
215
- Future <Uri > buildLib (
216
- BuildInput input,
217
- String workingDirectory,
218
- bool treeshake,
219
- ) async {
220
- final crateNameFixed = crateName.replaceAll ('-' , '_' );
221
- final libFileName = input.config.filename (treeshake)(crateNameFixed);
222
- final libFileUri = input.outputDirectory.resolve (libFileName);
223
-
224
- final code = input.config.code;
225
- final targetOS = code.targetOS;
226
- final targetArchitecture = code.targetArchitecture;
227
- final buildStatic = input.config.buildStatic (treeshake);
228
-
229
- final isNoStd = _isNoStdTarget ((targetOS, targetArchitecture));
230
- final target = asRustTarget (input);
231
-
232
- if (! isNoStd) {
233
- final rustArguments = ['target' , 'add' , target];
234
- await runProcess (
235
- 'rustup' ,
236
- rustArguments,
237
- workingDirectory: workingDirectory,
238
- );
239
- }
240
- final stdFeatures = ['logging' , 'simple_logger' ];
241
- final noStdFeatures = ['libc_alloc' , 'panic_handler' ];
242
- final features = {
243
- 'default_components' ,
244
- 'icu_collator' ,
245
- 'icu_datetime' ,
246
- 'icu_list' ,
247
- 'icu_decimal' ,
248
- 'icu_plurals' ,
249
- 'compiled_data' ,
250
- 'buffer_provider' ,
251
- 'experimental_components' ,
252
- ...(isNoStd ? noStdFeatures : stdFeatures),
253
- };
254
- final arguments = [
255
- if (buildStatic || isNoStd) '+nightly' ,
256
- 'rustc' ,
257
- '--manifest-path=$workingDirectory /ffi/capi/Cargo.toml' ,
258
- '--crate-type=${buildStatic ? 'staticlib' : 'cdylib' }' ,
259
- '--release' ,
260
- '--config=profile.release.panic="abort"' ,
261
- '--config=profile.release.codegen-units=1' ,
262
- '--no-default-features' ,
263
- '--features=${features .join (',' )}' ,
264
- if (isNoStd) '-Zbuild-std=core,alloc' ,
265
- if (buildStatic || isNoStd) ...[
266
- '-Zbuild-std=std,panic_abort' ,
267
- '-Zbuild-std-features=panic_immediate_abort' ,
268
- ],
269
- '--target=$target ' ,
270
- ];
271
- await runProcess ('cargo' , arguments, workingDirectory: workingDirectory);
272
-
273
- final builtPath = path.join (
274
- workingDirectory,
275
- 'target' ,
276
- target,
277
- 'release' ,
278
- libFileName,
279
- );
280
- final file = File (builtPath);
281
- if (! (await file.exists ())) {
282
- throw FileSystemException ('Building the dylib failed' , builtPath);
283
- }
284
- await file.copy (libFileUri.toFilePath (windows: Platform .isWindows));
285
- return libFileUri;
286
- }
287
-
288
- String asRustTarget (BuildInput input) {
289
- final rustTarget = _asRustTarget (
290
- input.config.code.targetOS,
291
- input.config.code.targetArchitecture,
292
- input.config.code.targetOS == OS .iOS &&
293
- input.config.code.iOS.targetSdk == IOSSdk .iPhoneSimulator,
294
- );
295
- return rustTarget;
296
- }
297
-
298
- String _asRustTarget (OS os, Architecture ? architecture, bool isSimulator) {
299
- if (os == OS .iOS && architecture == Architecture .arm64 && isSimulator) {
300
- return 'aarch64-apple-ios-sim' ;
301
- }
302
- return switch ((os, architecture)) {
303
- (OS .android, Architecture .arm) => 'armv7-linux-androideabi' ,
304
- (OS .android, Architecture .arm64) => 'aarch64-linux-android' ,
305
- (OS .android, Architecture .ia32) => 'i686-linux-android' ,
306
- (OS .android, Architecture .riscv64) => 'riscv64-linux-android' ,
307
- (OS .android, Architecture .x64) => 'x86_64-linux-android' ,
308
- (OS .fuchsia, Architecture .arm64) => 'aarch64-unknown-fuchsia' ,
309
- (OS .fuchsia, Architecture .x64) => 'x86_64-unknown-fuchsia' ,
310
- (OS .iOS, Architecture .arm64) => 'aarch64-apple-ios' ,
311
- (OS .iOS, Architecture .x64) => 'x86_64-apple-ios' ,
312
- (OS .linux, Architecture .arm) => 'armv7-unknown-linux-gnueabihf' ,
313
- (OS .linux, Architecture .arm64) => 'aarch64-unknown-linux-gnu' ,
314
- (OS .linux, Architecture .ia32) => 'i686-unknown-linux-gnu' ,
315
- (OS .linux, Architecture .riscv32) => 'riscv32gc-unknown-linux-gnu' ,
316
- (OS .linux, Architecture .riscv64) => 'riscv64gc-unknown-linux-gnu' ,
317
- (OS .linux, Architecture .x64) => 'x86_64-unknown-linux-gnu' ,
318
- (OS .macOS, Architecture .arm64) => 'aarch64-apple-darwin' ,
319
- (OS .macOS, Architecture .x64) => 'x86_64-apple-darwin' ,
320
- (OS .windows, Architecture .arm64) => 'aarch64-pc-windows-msvc' ,
321
- (OS .windows, Architecture .ia32) => 'i686-pc-windows-msvc' ,
322
- (OS .windows, Architecture .x64) => 'x86_64-pc-windows-msvc' ,
323
- (_, _) =>
324
- throw UnimplementedError (
325
- 'Target ${(os , architecture )} not available for rust' ,
326
- ),
327
- };
328
- }
329
-
330
- bool _isNoStdTarget ((OS os, Architecture ? architecture) arg) => [
331
- (OS .android, Architecture .riscv64),
332
- (OS .linux, Architecture .riscv64),
333
- ].contains (arg);
334
-
335
231
extension on BuildConfig {
336
232
bool buildStatic (bool treeshake) =>
337
233
code.linkModePreference == LinkModePreference .static ||
0 commit comments