tikv / jemallocator

Rust allocator using jemalloc as a backend
Other
364 stars 62 forks source link

Cross compilation with sysroot #100

Open dudycz opened 3 months ago

dudycz commented 3 months ago

Hello,

I have a project which is cross compiling successfully to aarch64 target using my sdk (sysroot).

Problem starts when I add jemalloc dependency: configure script executed during jemalloc build fails due to missing standard libs. I checked config.log and there are few entries suggesting that prefix was passed from cargo down to configure, but maybe there is something missing? When I export in shell environment variable: CFLAGS="--sysroot=/path/to/aarch64-linux-gnu" it works.

BusyJay commented 3 months ago

jemalloc-sys detects compiler by using cc crate, as long as cross compile works for cc, it should work for jemAlloc-sys.

dudycz commented 3 months ago

I don't know what exactly failed, but when I tried to cross compile my project (without jemalloc) to aarch64 it failed on linking the same system libs (libcrt, etc.). Then I figured out that I should add appropriate section to .cargo/config.toml with path to my sysroot:

[target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" ar = "aarch64-linux-gnu-ar" rustflags = ["-C", "link-arg=--sysroot=sdk/sysroots/aarch64-linux-gnu"]

After that step, everything started to work. And then when I added jemalloc, its configure script failed on linking giving the same error like cargo build before adding path to sysroot. So maybe this is some issue with cc crate? Or maybe it would be better to inherit configuration from cargo config?