Skip to content

Commit

Permalink
ffibake
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jan 5, 2023
1 parent 60ef306 commit 32afdd1
Show file tree
Hide file tree
Showing 29 changed files with 525 additions and 347 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ provider/testdata/data/icuexport/** linguist-generated=true
ffi/diplomat/c/include/** linguist-generated=true
ffi/diplomat/cpp/include/** linguist-generated=true
ffi/diplomat/cpp/docs/** linguist-generated=true
ffi/diplomat/js/include//** linguist-generated=true
ffi/diplomat/js/include/** linguist-generated=true
ffi/diplomat/js/docs/** linguist-generated=true
*.rs.data linguist-language=Rust
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.

8 changes: 5 additions & 3 deletions ffi/diplomat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ all-features = true
skip_optional_dependencies = true
# 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
# serde enables dependency features but buffer_provider affects the actual code
denylist = ["bench", "logging"]

# Please keep the features list in sync with the icu_capi_staticlib/icu_capi_cdylib crates
[features]
default = ["any_provider"]
default = []
any_provider = []
buffer_provider = [
"dep:icu_provider_blob",
Expand All @@ -63,7 +62,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 @@ -94,6 +93,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
14 changes: 14 additions & 0 deletions ffi/diplomat/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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 --features bin,icu_segmenter -- --format mod --use-separate-crates --keys none --out empty_bake
println!(
"cargo:rustc-env=ICU4X_FFI_BAKED_ROOT={}/empty_bake",
std::env::var("CARGO_MANIFEST_DIR").unwrap()
);
}
}
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 --no-default-features

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 --features bin -- --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 --features bin,icu_segmenter -- --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

0 comments on commit 32afdd1

Please sign in to comment.