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

FFI baked data #2947

Closed
wants to merge 11 commits into from
Closed
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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/capi_cdylib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ icu_provider = { version = "1.0.0", path = "../../provider/core", default-featur
# Please keep features/cargo-all-features lists in sync with the icu_capi crate
[features]
default = ["icu_capi/default"]
custom_bake_data = ["icu_capi/custom_bake_data"]
any_provider = ["icu_capi/any_provider"]
buffer_provider = ["icu_capi/buffer_provider"]
provider_fs = ["icu_capi/provider_fs"] # Indirectly implies buffer_provider
Expand Down
1 change: 1 addition & 0 deletions ffi/capi_staticlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ icu_provider = { version = "1.0.0", path = "../../provider/core", default-featur
# Please keep features/cargo-all-features lists in sync with the icu_capi crate
[features]
default = ["icu_capi/default"]
custom_bake_data = ["icu_capi/custom_bake_data"]
any_provider = ["icu_capi/any_provider"]
buffer_provider = ["icu_capi/buffer_provider"]
provider_fs = ["icu_capi/provider_fs"] # Indirectly implies buffer_provider
Expand Down
10 changes: 7 additions & 3 deletions ffi/diplomat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ all-features = true
[package.metadata.cargo-all-features]
# Bench feature gets tested separately and is only relevant for CI.
# logging enables a feature of a dependency that has no externally visible API changes
denylist = ["bench", "logging", "cpp_default", "wasm_default"]
denylist = ["bench", "logging", "cpp_default", "wasm_default", "custom_bake_data"]

# Please keep the features list in sync with the icu_capi_staticlib/icu_capi_cdylib crates
[features]
default = ["any_provider"]
default = ["custom_bake_data"]
custom_bake_data = []
any_provider = []
buffer_provider = [
"dep:icu_provider_blob",
Expand All @@ -60,7 +61,7 @@ logging = ["icu_provider/log_error_context", "dep:log"]
simple_logger = ["dep:simple_logger"]

# meta feature for things we enable by default in C and C++
cpp_default = ["provider_test", "logging", "simple_logger"]
cpp_default = ["provider_test", "any_provider", "logging", "simple_logger"]

# meta feature for things we enable by default in wasm
wasm_default = ["buffer_provider", "logging"]
Expand Down Expand Up @@ -91,6 +92,9 @@ serde = { version = "1.0", default-features = false, optional = true }

icu_testdata = { version = "1.0.0", path = "../../provider/testdata", optional = true, features = ["icu_segmenter"] }

# databake
zerovec = { version = "*", path = "../../utils/zerovec" }

# Run `cargo make diplomat-install` to get the right diplomat binary installed
# The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."`
# Since this crate is published, Diplomat must be published preceding a new ICU4X release but may use git versions in between
Expand Down
11 changes: 11 additions & 0 deletions ffi/diplomat/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

fn main() {
if std::env::var("ICU4X_FFI_BAKED_ROOT").is_err() {
// Empty data generated with
// cargo run -p icu_datagen -- --format mod --use-separate-crates --keys none --locales none --out empty_bake
println!("cargo:rustc-env=ICU4X_FFI_BAKED_ROOT=../empty_bake");
}
}
3 changes: 1 addition & 2 deletions ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ optim*
*.elf
*.o
a.out.dSYM
decimal-bn-en.postcard
decimal_bn_en.h
baked
32 changes: 15 additions & 17 deletions ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,49 @@ GCC := gcc
CLANG := clang-14
LLD := lld-14

export ICU4X_FFI_BAKED_ROOT = $(dir $(realpath $(lastword $(MAKEFILE_LIST))))baked

../../../../../target/debug/libicu_capi_staticlib.a: $(ALL_RUST)
cargo build -p icu_capi_staticlib --no-default-features --features buffer_provider
../../../../../target/debug/libicu_capi_staticlib.a: $(ALL_RUST) $(ICU4X_FFI_BAKED_ROOT)
cargo build -p icu_capi_staticlib

icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a: $(ALL_RUST)
icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a: $(ALL_RUST) $(ICU4X_FFI_BAKED_ROOT)
cd icu_capi_staticlib_tiny && \
RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +${ICU4X_NIGHTLY_TOOLCHAIN} panic-abort-build --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +$(ICU4X_NIGHTLY_TOOLCHAIN) panic-abort-build --target x86_64-unknown-linux-gnu

icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a: $(ALL_RUST)
icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a: $(ALL_RUST) $(ICU4X_FFI_BAKED_ROOT)
cd icu_capi_staticlib_tiny && \
RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +${ICU4X_NIGHTLY_TOOLCHAIN} panic-abort-build --target x86_64-unknown-linux-gnu --profile=release-opt-size
RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +$(ICU4X_NIGHTLY_TOOLCHAIN) panic-abort-build --target x86_64-unknown-linux-gnu --profile=release-opt-size

decimal-bn-en.postcard:
cargo run -p icu_datagen -- --locales en bn --keys "decimal/symbols@1" --cldr-root ../../../../../provider/testdata/data/cldr/ --format blob --out decimal-bn-en.postcard

decimal_bn_en.h: decimal-bn-en.postcard
xxd -i -C decimal-bn-en.postcard > decimal_bn_en.h
$(ICU4X_FFI_BAKED_ROOT):
cargo run -p icu_datagen -- --locales en bn --keys "decimal/symbols@1" --cldr-root ../../../../../provider/testdata/data/cldr/ --format mod --use-separate-crates --out ${ICU4X_FFI_BAKED_ROOT}

# Naive target: no optimizations, full std
optim0.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c decimal_bn_en.h
optim0.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c
$(GCC) test.c ../../../../../target/debug/libicu_capi_staticlib.a -ldl -lpthread -lm -g -o optim0.elf

# optim.elf: gcc with maximum link-time code stripping (gc-sections and strip-all)
optim1.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c decimal_bn_en.h
optim1.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c
$(GCC) -fdata-sections -ffunction-sections test.c ../../../../../target/debug/libicu_capi_staticlib.a -ldl -lpthread -lm -g -o optim1.elf -Wl,--gc-sections -Wl,--strip-all

# optim2.elf: clang single-step with gc-sections
optim2.elf: icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a $(ALL_HEADERS) test.c decimal_bn_en.h
optim2.elf: icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a $(ALL_HEADERS) test.c
$(CLANG) -flto -fdata-sections -ffunction-sections test.c icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a -g -o optim2.elf -Wl,--gc-sections

optim3.o: $(ALL_HEADERS) test.c decimal_bn_en.h
optim3.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -g -o optim3.o

# optim3.elf: clang two-step with lld, debug mode
optim3.elf: optim3.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim3.elf optim3.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a -Wl,--gc-sections

optim4.o: $(ALL_HEADERS) test.c decimal_bn_en.h
optim4.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -g -o optim4.o

# optim4.elf: clang two-step with lld, release mode with debug symbols
optim4.elf: optim4.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim4.elf optim4.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a -Wl,--gc-sections

optim5.o: $(ALL_HEADERS) test.c decimal_bn_en.h
optim5.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -o optim5.o

# optim5.elf: clang two-step with lld, release mode stripped of debug symbols
Expand Down
Loading