Skip to content

Commit 36ec7a9

Browse files
committed
Works now
1 parent c8be307 commit 36ec7a9

File tree

5 files changed

+55
-59
lines changed

5 files changed

+55
-59
lines changed

pkgs/intl4x/example_native/pubspec.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ dependencies:
1313
dev_dependencies:
1414
lints: ^6.0.0
1515

16-
hook:
17-
intl4x:
18-
buildMode: checkout
19-
checkoutPath: ../../../submodules/icu4x
20-
treeshake: true
16+
hooks:
17+
user_defines:
18+
intl4x:
19+
buildMode: checkout
20+
checkoutPath: ../../../submodules/icu4x

pkgs/intl4x/hook/build.dart

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,48 @@ import 'dart:io';
77
import 'package:crypto/crypto.dart' show sha256;
88
import 'package:intl4x/src/hook_helpers/build_libs.g.dart' show buildLib;
99
import 'package:intl4x/src/hook_helpers/build_options.dart'
10-
show BuildModeEnum, getBuildOptions;
10+
show BuildModeEnum, BuildOptions, getBuildOptions;
1111
import 'package:intl4x/src/hook_helpers/hashes.dart' show fileHashes;
1212
import 'package:intl4x/src/hook_helpers/shared.dart' show assetId, package;
1313
import 'package:intl4x/src/hook_helpers/version.dart' show version;
1414
import 'package:native_assets_cli/code_assets.dart';
1515

1616
void main(List<String> args) async {
1717
await build(args, (input, output) async {
18-
final buildOptions = await getBuildOptions(
19-
input.outputDirectory.toFilePath(),
20-
);
21-
if (buildOptions == null) {
18+
BuildOptions buildOptions;
19+
try {
20+
buildOptions = await getBuildOptions(input.userDefines);
21+
} catch (e) {
2222
throw ArgumentError('''
23+
Error: $e
24+
25+
26+
Set the build mode with either `fetch`, `local`, or `checkout` by writing into your pubspec:
2327
24-
Unknown build mode for icu4x. Set the build mode with either `fetch`, `local`, or `checkout` by writing into your pubspec:
2528
* fetch: Fetch the precompiled binary from a CDN.
2629
```
27-
...
28-
hook:
29-
intl4x:
30-
buildMode: fetch
31-
...
30+
hooks:
31+
user_defines:
32+
intl4x:
33+
buildMode: fetch
3234
```
35+
3336
* local: Use a locally existing binary at the environment variable `LOCAL_ICU4X_BINARY`.
3437
```
35-
...
36-
hook:
37-
intl4x:
38-
buildMode: local
39-
localDylibPath: path/to/dylib.so
40-
...
38+
hooks:
39+
user_defines:
40+
intl4x:
41+
buildMode: local
42+
localDylibPath: path/to/dylib.so
4143
```
44+
4245
* checkout: Build a fresh library from a local git checkout of the icu4x repository.
4346
```
44-
...
45-
hook:
46-
intl4x:
47-
buildMode: checkout
48-
checkoutPath: path/to/checkout
49-
...
47+
hooks:
48+
user_defines:
49+
intl4x:
50+
buildMode: checkout
51+
checkoutPath: path/to/checkout
5052
```
5153
5254
''');
@@ -70,17 +72,13 @@ hook:
7072
final builtLibrary = await buildMode.build();
7173
// For debugging purposes
7274
// ignore: deprecated_member_use
73-
output.addMetadatum('ICU4X_BUILD_MODE', buildOptions.buildMode.name);
75+
output.metadata.addAll({'ICU4X_BUILD_MODE': buildOptions.buildMode.name});
7476

75-
final targetOS = input.config.code.targetOS;
76-
final targetArchitecture = input.config.code.targetArchitecture;
7777
output.assets.code.add(
7878
CodeAsset(
7979
package: package,
8080
name: assetId,
8181
linkMode: DynamicLoadingBundled(),
82-
architecture: targetArchitecture,
83-
os: targetOS,
8482
file: builtLibrary,
8583
),
8684
routing:
@@ -156,12 +154,12 @@ final class FetchMode extends BuildMode {
156154
}
157155

158156
final class LocalMode extends BuildMode {
159-
final String? localPath;
157+
final Uri? localPath;
160158
LocalMode(super.input, this.localPath, super.treeshake);
161159

162160
String get _localLibraryPath {
163161
if (localPath != null) {
164-
return localPath!;
162+
return localPath!.toFilePath(windows: Platform.isWindows);
165163
}
166164
throw ArgumentError(
167165
'`LOCAL_ICU4X_BINARY` is empty. '
@@ -190,7 +188,7 @@ final class LocalMode extends BuildMode {
190188
}
191189

192190
final class CheckoutMode extends BuildMode {
193-
final String? checkoutPath;
191+
final Uri? checkoutPath;
194192

195193
CheckoutMode(super.input, this.checkoutPath, super.treeshake);
196194

@@ -209,23 +207,23 @@ final class CheckoutMode extends BuildMode {
209207
input.config.buildStatic(treeshake),
210208
input.config.code.targetOS == OS.iOS &&
211209
input.config.code.iOS.targetSdk == IOSSdk.iPhoneSimulator,
212-
Directory(checkoutPath!),
210+
Directory.fromUri(checkoutPath!),
213211
[
214212
'icu_collator',
215213
'icu_datetime',
216214
'icu_list',
217215
'icu_decimal',
218216
'icu_plurals',
219217
'experimental_components',
218+
'default_components',
219+
'compiled_data',
220220
],
221221
);
222222
return builtLib.uri;
223223
}
224224

225225
@override
226-
List<Uri> get dependencies => [
227-
Uri.directory(checkoutPath!).resolve('Cargo.lock'),
228-
];
226+
List<Uri> get dependencies => [checkoutPath!.resolve('Cargo.lock')];
229227
}
230228

231229
extension on BuildConfig {

pkgs/intl4x/lib/src/hook_helpers/build_options.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import 'dart:convert' show JsonEncoder;
66
import 'dart:io';
77

8+
// ignore: implementation_imports
9+
import 'package:native_assets_cli/src/config.dart';
810
import 'package:path/path.dart' as path;
911
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
1012

11-
Future<BuildOptions?> getBuildOptions(String searchDir) async {
12-
final (map, dir) = await readOptionsFromPubspec(searchDir);
13-
print('Reading build options from $map');
14-
final buildOptions = BuildOptions.fromMap(map?['intl4x'] as Map? ?? {}, dir);
13+
Future<BuildOptions> getBuildOptions(HookInputUserDefines userDefines) async {
14+
final buildOptions = BuildOptions.fromDefines(userDefines);
1515
print('Got build options: ${buildOptions.toJson()}');
1616
return buildOptions;
1717
}
@@ -38,8 +38,8 @@ enum BuildModeEnum { local, checkout, fetch }
3838

3939
class BuildOptions {
4040
final BuildModeEnum buildMode;
41-
final String? localDylibPath;
42-
final String? checkoutPath;
41+
final Uri? localDylibPath;
42+
final Uri? checkoutPath;
4343
final bool? treeshake;
4444

4545
BuildOptions({
@@ -52,22 +52,20 @@ class BuildOptions {
5252
Map<String, dynamic> toMap() {
5353
return {
5454
'buildMode': buildMode.name,
55-
if (localDylibPath != null) 'localDylibPath': localDylibPath,
56-
if (checkoutPath != null) 'checkoutPath': checkoutPath,
55+
if (localDylibPath != null) 'localDylibPath': localDylibPath.toString(),
56+
if (checkoutPath != null) 'checkoutPath': checkoutPath.toString(),
5757
if (treeshake != null) 'treeshake': treeshake.toString(),
5858
};
5959
}
6060

61-
factory BuildOptions.fromMap(Map map, Directory dir) {
62-
final localPath = map['localDylibPath'] as String?;
63-
final checkoutPath = map['checkoutPath'] as String?;
61+
factory BuildOptions.fromDefines(HookInputUserDefines defines) {
6462
return BuildOptions(
6563
buildMode: BuildModeEnum.values.firstWhere(
66-
(element) => element.name == map['buildMode'],
64+
(element) => element.name == defines['buildMode'],
6765
),
68-
localDylibPath: localPath != null ? getPath(dir, localPath) : null,
69-
checkoutPath: checkoutPath != null ? getPath(dir, checkoutPath) : null,
70-
treeshake: map['treeshake'] == true,
66+
localDylibPath: defines.path('localDylibPath'),
67+
checkoutPath: defines.path('checkoutPath'),
68+
treeshake: (defines['treeshake'] ?? true) == true,
7169
);
7270
}
7371

pkgs/intl4x/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dependencies:
2626
ffi: ^2.1.0
2727
logging: ^1.3.0
2828
meta: ^1.12.0
29-
native_assets_cli: ^0.16.0
30-
native_toolchain_c: ^0.13.0
29+
native_assets_cli: ^0.17.0
30+
native_toolchain_c: ^0.14.0
3131
path: ^1.9.0
3232
record_use: ^0.3.0
3333
yaml: ^3.1.3

pkgs/intl4x/tool/write_option_file.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Future<void> main(List<String> args) async {
1717
final buildOptions = switch (buildMode) {
1818
BuildModeEnum.local => BuildOptions(
1919
buildMode: buildMode,
20-
localDylibPath: pathString,
20+
localDylibPath: Uri.parse(pathString!),
2121
),
2222
BuildModeEnum.checkout => BuildOptions(
2323
buildMode: buildMode,
24-
checkoutPath: pathString,
24+
checkoutPath: Uri.parse(pathString!),
2525
),
2626
BuildModeEnum.fetch => BuildOptions(buildMode: buildMode),
2727
};

0 commit comments

Comments
 (0)