Skip to content

Issues when compiling Rust library project to a static library  #37

@huming2207

Description

@huming2207

Hi all,

I'm trying to compile ttf-parser to a static library for another ESP-IDF C/C++ project. It has a C binding and it should just work as long as I change the target type from cdylib to staticlib (am I right? or have I forgot something?). However it didn't work somehow when opt-level is not 0 or s. Here's what I have done:

  1. I used the docker image, by docker pull espressif/idf-rust-examples then docker run -it espressif/idf-rust-examples
  2. I cloned the ttf-parser project, by: git clone https://github.com/RazrFalcon/ttf-parser
  3. Then I go to the c-api directory. I added a .cargo/config.toml, content listed below:
[build]
# Uncomment the relevant target for your chip here (ESP32, ESP32-S2 or ESP32-C3)
target = "xtensa-esp32-espidf"
#target = "xtensa-esp32s2-espidf"
#target = "riscv32imc-esp-espidf"

[target.xtensa-esp32-espidf]
linker = "ldproxy"

[target.xtensa-esp32s2-espidf]
linker = "ldproxy"

[target.riscv32imc-esp-espidf]
linker = "ldproxy"

[patch.crates-io]
# This patch is a temporary workaround necessary until Rust 1.55 is out
# You DON'T need it with stock nightly Rust 1.56 (but stock nightly only supports the ESP32-C3 chip)
libc = { git = "https://github.com/ivmarkov/libc.git" }

[unstable]
configurable-env = true # No longer necessary since 1.56, as it was stabilized: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/features.rs#L698
extra-link-arg = true   # No longer necessary since 1.56, as it was stabilized: https://github.com/rust-lang/cargo/blob/master/src/cargo/core/features.rs#L695
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
patch-in-config = true
  1. I run cargo build --release --verbose. Then something goes wrong. Here are a few different variants:
  • If I leave the lto = true and default release opt-level (should be 3?) in the Cargo.toml, rustc constantly uses 100% CPU and never finish compiling (at least still running after 3 minutes on a machine with Ryzen 3700X, 32GB RAM)
  • If I comment lto = true out and default release opt-level (should be 3?) , rustc will not lock up. But instead it gives me this output:
warning: Patch `libc v0.2.101 (https://github.com/ivmarkov/libc.git#7e83ba0a)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Updating git repository `https://github.com/ivmarkov/libc.git`
warning: Patch `libc v0.2.101 (https://github.com/ivmarkov/libc.git#7e83ba0a)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
       Fresh core v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/core)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh cc v1.0.69
       Fresh rustc-std-workspace-core v1.99.0 (/opt/esp/lib/rustlib/src/rust/library/rustc-std-workspace-core)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh compiler_builtins v0.1.49
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh libc v0.2.98 (https://github.com/rust-lang/libc.git#67562637)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh alloc v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/alloc)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh cfg-if v0.1.10
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh rustc-demangle v0.1.20
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh rustc-std-workspace-alloc v1.99.0 (/opt/esp/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh unwind v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/unwind)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh panic_abort v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/panic_abort)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh hashbrown v0.11.2
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh std_detect v0.1.5 (/opt/esp/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh panic_unwind v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/panic_unwind)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh std v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/std)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
       Fresh proc_macro v0.0.0 (/opt/esp/lib/rustlib/src/rust/library/proc_macro)
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
   Compiling ttf-parser v0.12.3 (/opt/ttf-parser)
     Running `rustc --crate-name ttf_parser --edition=2018 /opt/ttf-parser/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="std"' --cfg 'feature="variable-fonts"' -C metadata=b7db5016109f670c -C extra-filename=-b7db5016109f670c --out-dir /opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps --target xtensa-esp32-espidf -C linker=ldproxy -L dependency=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps -L dependency=/opt/ttf-parser/c-api/target/release/deps --extern 'noprelude:alloc=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/liballoc-2902dfbac9bdd6ca.rmeta' --extern 'noprelude:compiler_builtins=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcompiler_builtins-5cb2d211fd6af220.rmeta' --extern 'noprelude:core=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcore-3cff502e5da9da9c.rmeta' --extern 'noprelude:panic_abort=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_abort-0042c62788b76179.rmeta' --extern 'noprelude:panic_unwind=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_unwind-6ec9d840d190d1d7.rmeta' --extern 'noprelude:proc_macro=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libproc_macro-080b393debb41506.rmeta' --extern 'noprelude:std=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libstd-559d5acfa07b308c.rmeta' -Z unstable-options`
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
LLVM ERROR: fixup value out of range
error: could not compile `ttf-parser`

Caused by:
  process didn't exit successfully: `rustc --crate-name ttf_parser --edition=2018 /opt/ttf-parser/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="std"' --cfg 'feature="variable-fonts"' -C metadata=b7db5016109f670c -C extra-filename=-b7db5016109f670c --out-dir /opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps --target xtensa-esp32-espidf -C linker=ldproxy -L dependency=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps -L dependency=/opt/ttf-parser/c-api/target/release/deps --extern 'noprelude:alloc=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/liballoc-2902dfbac9bdd6ca.rmeta' --extern 'noprelude:compiler_builtins=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcompiler_builtins-5cb2d211fd6af220.rmeta' --extern 'noprelude:core=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcore-3cff502e5da9da9c.rmeta' --extern 'noprelude:panic_abort=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_abort-0042c62788b76179.rmeta' --extern 'noprelude:panic_unwind=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_unwind-6ec9d840d190d1d7.rmeta' --extern 'noprelude:proc_macro=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libproc_macro-080b393debb41506.rmeta' --extern 'noprelude:std=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libstd-559d5acfa07b308c.rmeta' -Z unstable-options` (exit status: 101)

  • If I set debug = true and opt-level = "z", it gives me:
   Compiling ttf-parser v0.12.3 (/opt/ttf-parser)
     Running `rustc --crate-name ttf_parser --edition=2018 /opt/ttf-parser/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=z -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="std"' --cfg 'feature="variable-fonts"' -C metadata=47d4919b23a5bfb9 -C extra-filename=-47d4919b23a5bfb9 --out-dir /opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps --target xtensa-esp32-espidf -C linker=ldproxy -L dependency=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps -L dependency=/opt/ttf-parser/c-api/target/release/deps --extern 'noprelude:alloc=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/liballoc-6e011642604099cb.rmeta' --extern 'noprelude:compiler_builtins=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcompiler_builtins-6ee7ed1b085d2764.rmeta' --extern 'noprelude:core=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcore-41b494a1d5172bd1.rmeta' --extern 'noprelude:panic_abort=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_abort-09026d116c1a3ad5.rmeta' --extern 'noprelude:panic_unwind=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_unwind-f0b56e4ce10f80a5.rmeta' --extern 'noprelude:proc_macro=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libproc_macro-fd87d4d48a2fd788.rmeta' --extern 'noprelude:std=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libstd-259244ca692541bb.rmeta' -Z unstable-options`
'+memctl' is not a recognized feature for this target (ignoring feature)
'+memctl' is not a recognized feature for this target (ignoring feature)
LLVM ERROR: Error while trying to spill A14 from class AR: Cannot scavenge register without an emergency spill slot!
error: could not compile `ttf-parser`

Caused by:
  process didn't exit successfully: `rustc --crate-name ttf_parser --edition=2018 /opt/ttf-parser/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=z -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="std"' --cfg 'feature="variable-fonts"' -C metadata=47d4919b23a5bfb9 -C extra-filename=-47d4919b23a5bfb9 --out-dir /opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps --target xtensa-esp32-espidf -C linker=ldproxy -L dependency=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps -L dependency=/opt/ttf-parser/c-api/target/release/deps --extern 'noprelude:alloc=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/liballoc-6e011642604099cb.rmeta' --extern 'noprelude:compiler_builtins=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcompiler_builtins-6ee7ed1b085d2764.rmeta' --extern 'noprelude:core=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libcore-41b494a1d5172bd1.rmeta' --extern 'noprelude:panic_abort=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_abort-09026d116c1a3ad5.rmeta' --extern 'noprelude:panic_unwind=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libpanic_unwind-f0b56e4ce10f80a5.rmeta' --extern 'noprelude:proc_macro=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libproc_macro-fd87d4d48a2fd788.rmeta' --extern 'noprelude:std=/opt/ttf-parser/c-api/target/xtensa-esp32-espidf/release/deps/libstd-259244ca692541bb.rmeta' -Z unstable-options` (exit status: 101)

  • If I set opt-level = 0 in the Cargo.toml, it can compile, but '+memctl' is not a recognized feature for this target (ignoring feature) warning still shows up
  • If I set opt-level = "s", in the Cargo.toml, it can compile, but '+memctl' is not a recognized feature for this target (ignoring feature) warning still shows up
  • If I set opt-level = "s" and lto = true in the Cargo.toml, it can compile, but '+memctl' is not a recognized feature for this target (ignoring feature) warning still shows up

I would like to know is this a compiler bug or I somehow misused something? Any suggestions? Thanks in advance!

Regards,
Jackson

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions