Skip to content

Commit

Permalink
Switch to copying ICU4X Dart files (#860)
Browse files Browse the repository at this point in the history
* Switch to copying ICU4X files instead of using symlinks

* Switch files to copies

* Switch to Dart fix branch

* Use dart format

* Format files

* Add changelog entry

* Add flags to building libraries

* Add gitattributes

* Add newline
  • Loading branch information
mosuem authored Jul 24, 2024
1 parent 332b1a3 commit 8d63e87
Show file tree
Hide file tree
Showing 129 changed files with 14,497 additions and 146 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkgs/intl4x/lib/src/bindings linguist-generated=true
42 changes: 22 additions & 20 deletions .github/workflows/intl4x_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ permissions:
on:
push:
tags:
- 'intl4x-v.*'
- 'intl4x-icu*'
schedule:
- cron: '0 0 * * 0' # weekly
workflow_dispatch:

jobs:
dart-libs:
name: "Build Dart binaries"
name: Build Dart binaries
strategy:
fail-fast: false
matrix:
Expand All @@ -21,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
submodules: 'true'
submodules: true

- name: Install Rust toolchains
run: |
Expand Down Expand Up @@ -59,14 +61,14 @@ jobs:
cd ffi/dart
dart pub get
cd ../..
dart run ffi/dart/tool/build_libs.dart bin/android_arm android_arm
dart run ffi/dart/tool/build_libs.dart bin/android_arm64 android_arm64
dart run ffi/dart/tool/build_libs.dart bin/android_ia32 android_ia32
dart run ffi/dart/tool/build_libs.dart bin/android_x64 android_x64
dart run ffi/dart/tool/build_libs.dart bin/linux_arm linux_arm
dart run ffi/dart/tool/build_libs.dart bin/linux_arm64 linux_arm64
dart run ffi/dart/tool/build_libs.dart bin/linux_riscv64 linux_riscv64
dart run ffi/dart/tool/build_libs.dart bin/linux_x64 linux_x64
dart run ffi/dart/tool/build_libs.dart bin/android_arm android_arm dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/android_arm64 android_arm64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/android_ia32 android_ia32 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/android_x64 android_x64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/linux_arm linux_arm dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/linux_arm64 linux_arm64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/linux_riscv64 linux_riscv64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/linux_x64 linux_x64 dynamic default_components,experimental_components
cargo run -p icu_datagen -- --locales full --keys all --format blob --out bin/full.postcard
Expand All @@ -93,11 +95,11 @@ jobs:
cd ffi/dart
dart pub get
cd ../..
dart run ffi/dart/tool/build_libs.dart bin/ios_arm ios_arm
dart run ffi/dart/tool/build_libs.dart bin/ios_arm64 ios_arm64
dart run ffi/dart/tool/build_libs.dart bin/ios_x64 ios_x64
dart run ffi/dart/tool/build_libs.dart bin/macos_arm64 macos_arm64
dart run ffi/dart/tool/build_libs.dart bin/macos_x64 macos_x64
dart run ffi/dart/tool/build_libs.dart bin/ios_arm ios_arm dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/ios_arm64 ios_arm64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/ios_x64 ios_x64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/macos_arm64 macos_arm64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/macos_x64 macos_x64 dynamic default_components,experimental_components
cd provider/datagen # avoid global feature resolution
rustup target add aarch64-apple-darwin
Expand All @@ -119,9 +121,9 @@ jobs:
cd ffi/dart
dart pub get
cd ../..
dart run ffi/dart/tool/build_libs.dart bin/windows_arm64 windows_arm64
dart run ffi/dart/tool/build_libs.dart bin/windows_ia32 windows_ia32
dart run ffi/dart/tool/build_libs.dart bin/windows_x64 windows_x64
dart run ffi/dart/tool/build_libs.dart bin/windows_arm64 windows_arm64 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/windows_ia32 windows_ia32 dynamic default_components,experimental_components
dart run ffi/dart/tool/build_libs.dart bin/windows_x64 windows_x64 dynamic default_components,experimental_components
cd provider/datagen # avoid global feature resolution
rustup target add aarch64-pc-windows-msvc
Expand Down Expand Up @@ -155,4 +157,4 @@ jobs:
with:
files: '**'
fail_on_unmatched_files: true
body: "Build artifacts for `package:intl4x`, based on ICU4X at ref ${{ env.icu_version }}"
body: "Build artifacts for `package:intl4x`, based on ICU4X at ref ${{ github.ref_name }}"
4 changes: 4 additions & 0 deletions pkgs/intl4x/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.2-wip

- Copy files instead of symlinking, for easier upgrading.

## 0.9.1

- Small fixes in imports
Expand Down
1 change: 0 additions & 1 deletion pkgs/intl4x/lib/src/bindings/AnyCalendarKind.g.dart

This file was deleted.

128 changes: 128 additions & 0 deletions pkgs/intl4x/lib/src/bindings/AnyCalendarKind.g.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// generated by diplomat-tool

part of 'lib.g.dart';

/// The various calendar types currently supported by [`Calendar`]
///
/// See the [Rust documentation for `AnyCalendarKind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html) for more information.
enum AnyCalendarKind {
/// The kind of an Iso calendar
iso,

/// The kind of a Gregorian calendar
gregorian,

/// The kind of a Buddhist calendar
buddhist,

/// The kind of a Japanese calendar with modern eras
japanese,

/// The kind of a Japanese calendar with modern and historic eras
japaneseExtended,

/// The kind of an Ethiopian calendar, with Amete Mihret era
ethiopian,

/// The kind of an Ethiopian calendar, with Amete Alem era
ethiopianAmeteAlem,

/// The kind of a Indian calendar
indian,

/// The kind of a Coptic calendar
coptic,

/// The kind of a Dangi calendar
dangi,

/// The kind of a Chinese calendar
chinese,

/// The kind of a Hebrew calendar
hebrew,

/// The kind of a Islamic civil calendar
islamicCivil,

/// The kind of a Islamic observational calendar
islamicObservational,

/// The kind of a Islamic tabular calendar
islamicTabular,

/// The kind of a Islamic Umm al-Qura calendar
islamicUmmAlQura,

/// The kind of a Persian calendar
persian,

/// The kind of a Roc calendar
roc;

/// Read the calendar type off of the -u-ca- extension on a locale.
///
/// Returns nothing if there is no calendar on the locale or if the locale's calendar
/// is not known or supported.
///
/// See the [Rust documentation for `get_for_locale`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html#method.get_for_locale) for more information.
static AnyCalendarKind? getForLocale(Locale locale) {
final result = _ICU4XAnyCalendarKind_get_for_locale(locale._ffi);
if (!result.isOk) {
return null;
}
return AnyCalendarKind.values[result.union.ok];
}

/// Obtain the calendar type given a BCP-47 -u-ca- extension string.
///
/// Returns nothing if the calendar is not known or supported.
///
/// See the [Rust documentation for `get_for_bcp47_value`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html#method.get_for_bcp47_value) for more information.
static AnyCalendarKind? getForBcp47(String s) {
final temp = ffi2.Arena();
final sView = s.utf8View;
final result =
_ICU4XAnyCalendarKind_get_for_bcp47(sView.allocIn(temp), sView.length);
temp.releaseAll();
if (!result.isOk) {
return null;
}
return AnyCalendarKind.values[result.union.ok];
}

/// Obtain the string suitable for use in the -u-ca- extension in a BCP47 locale.
///
/// See the [Rust documentation for `as_bcp47_string`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html#method.as_bcp47_string) for more information.
///
/// Throws [Error] on failure.
String get bcp47 {
final writeable = _Writeable();
final result = _ICU4XAnyCalendarKind_bcp47(index, writeable._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
}

@meta.ResourceIdentifier('ICU4XAnyCalendarKind_get_for_locale')
@ffi.Native<_ResultInt32Void Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XAnyCalendarKind_get_for_locale')
// ignore: non_constant_identifier_names
external _ResultInt32Void _ICU4XAnyCalendarKind_get_for_locale(
ffi.Pointer<ffi.Opaque> locale);

@meta.ResourceIdentifier('ICU4XAnyCalendarKind_get_for_bcp47')
@ffi.Native<_ResultInt32Void Function(ffi.Pointer<ffi.Uint8>, ffi.Size)>(
isLeaf: true, symbol: 'ICU4XAnyCalendarKind_get_for_bcp47')
// ignore: non_constant_identifier_names
external _ResultInt32Void _ICU4XAnyCalendarKind_get_for_bcp47(
ffi.Pointer<ffi.Uint8> sData, int sLength);

@meta.ResourceIdentifier('ICU4XAnyCalendarKind_bcp47')
@ffi.Native<_ResultVoidInt32 Function(ffi.Int32, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XAnyCalendarKind_bcp47')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XAnyCalendarKind_bcp47(
int self, ffi.Pointer<ffi.Opaque> writeable);
1 change: 0 additions & 1 deletion pkgs/intl4x/lib/src/bindings/Bcp47ToIanaMapper.g.dart

This file was deleted.

81 changes: 81 additions & 0 deletions pkgs/intl4x/lib/src/bindings/Bcp47ToIanaMapper.g.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// generated by diplomat-tool

part of 'lib.g.dart';

/// An object capable of mapping from a BCP-47 time zone ID to an IANA ID.
///
/// See the [Rust documentation for `IanaBcp47RoundTripMapper`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapper.html) for more information.
final class Bcp47ToIanaMapper implements ffi.Finalizable {
final ffi.Pointer<ffi.Opaque> _ffi;

// These are "used" in the sense that they keep dependencies alive
// ignore: unused_field
final core.List<Object> _selfEdge;

// This takes in a list of lifetime edges (including for &self borrows)
// corresponding to data this may borrow from. These should be flat arrays containing
// references to objects, and this object will hold on to them to keep them alive and
// maintain borrow validity.
Bcp47ToIanaMapper._fromFfi(this._ffi, this._selfEdge) {
if (_selfEdge.isEmpty) {
_finalizer.attach(this, _ffi.cast());
}
}

static final _finalizer = ffi.NativeFinalizer(
ffi.Native.addressOf(_ICU4XBcp47ToIanaMapper_destroy));

/// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapper.html#method.new) for more information.
///
/// Throws [Error] on failure.
factory Bcp47ToIanaMapper(DataProvider provider) {
final result = _ICU4XBcp47ToIanaMapper_create(provider._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return Bcp47ToIanaMapper._fromFfi(result.union.ok, []);
}

/// Writes out the canonical IANA time zone ID corresponding to the given BCP-47 ID.
///
/// See the [Rust documentation for `bcp47_to_iana`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapperBorrowed.html#method.bcp47_to_iana) for more information.
///
/// Throws [Error] on failure.
String operator [](String value) {
final temp = ffi2.Arena();
final valueView = value.utf8View;
final writeable = _Writeable();
final result = _ICU4XBcp47ToIanaMapper_get(
_ffi, valueView.allocIn(temp), valueView.length, writeable._ffi);
temp.releaseAll();
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
}

@meta.ResourceIdentifier('ICU4XBcp47ToIanaMapper_destroy')
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
isLeaf: true, symbol: 'ICU4XBcp47ToIanaMapper_destroy')
// ignore: non_constant_identifier_names
external void _ICU4XBcp47ToIanaMapper_destroy(ffi.Pointer<ffi.Void> self);

@meta.ResourceIdentifier('ICU4XBcp47ToIanaMapper_create')
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XBcp47ToIanaMapper_create')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _ICU4XBcp47ToIanaMapper_create(
ffi.Pointer<ffi.Opaque> provider);

@meta.ResourceIdentifier('ICU4XBcp47ToIanaMapper_get')
@ffi.Native<
_ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>,
ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XBcp47ToIanaMapper_get')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XBcp47ToIanaMapper_get(
ffi.Pointer<ffi.Opaque> self,
ffi.Pointer<ffi.Uint8> valueData,
int valueLength,
ffi.Pointer<ffi.Opaque> writeable);
1 change: 0 additions & 1 deletion pkgs/intl4x/lib/src/bindings/Bidi.g.dart

This file was deleted.

Loading

0 comments on commit 8d63e87

Please sign in to comment.