#How do I compile with target features my host doesn't have?

59 messages · Page 1 of 1 (latest)

narrow tiger
# boreal dome https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags

Hey sorry for reviving this old thread, but I'm looking for the exact opposite.
Passing a specific flag only to my build script compilation...

I'm compiling a build script in alpine that uses bindgen (and thus links dynamically to clang... static linking has other issues), but I can't set target-feature=-crt-static for thr build script 😦

boreal dome
#

How are you invoking bindgen?

narrow tiger
#

Thanks for the issue there, I was on my journey to find alternatives.
This is the issue that sums in up https://github.com/Zondax/docker-bolos/pull/23

but basically I just call binden::builder() and pass it a few flags, nothing extravagant

#

the issue is that by default it's +crt-static for alpine musl, and since I'm cross compiling to arm, RUSTFLAGS isn't considered.
I even tried using .cargo/config to set rustflags for the specific target, but now that you pointed that out it makes sense why it didn' t work

#

I'll read the issue you linked last and see if anything works for me

boreal dome
#

(I haven't tried this myself, but it seems like something that should work)

narrow tiger
#

that's actually what I tried

#
[target.x86_64-unknown-linux-musl]
rustflags = ["-Ctarget-feature=-crt-static"]
#

but that didn't work :/

boreal dome
#

Would you be able to flip the host and target, to have -Ctarget-feature=-crt-static be the default and the normal RUSTFLAGS be the override?

narrow tiger
#

wdym?

boreal dome
#

Like, have

[build]
rustflags = ["-Ctarget-feature=-crt-static"]

[target.my-arm-target]
rustflags = ["whatever"]
narrow tiger
#

I'll give it a shot, but I don't have much hope

#

tbh I don't have rustflags for arm target, but

#

yep, didn't work

#

There doesn't seem to be a solution on stable, but luckily there's one on nightly

boreal dome
#

Are you talking about -Zhost-config?

narrow tiger
#

yes

boreal dome
#

Yeah, I was just looking through the PR for that, it looks like what you want

narrow tiger
#

I'd love to get a workaround for "stable" since we are targeting stable

#

we actually only recently "enabled" nightly for build-std

#

but I wanted to keep it to a minimum

boreal dome
#

Hmm

#

Looking at the code, I don't see any reason why the [target.x86_64-unknown-linux-musl] solution shouldn't work

narrow tiger
#

isn't it ignored because it's a cargo build --target xyz?

boreal dome
#

It's the ordinary RUSTFLAGS that's supposed to be ignored

narrow tiger
#

can you share where you are looking?

narrow tiger
#

(btw that's a rather outdated fork)

#

2000+ commits behind

narrow tiger
#

yeah I was looking at that rn

#

but that seems to imply [host]

#

I was even thinking a workaround could be disabling build script and doing a custom thing, like launch a build with the right flags and whatever, but I didn't manage to look into it yet.
Very dirty, very universal

boreal dome
narrow tiger
#

host works perfectly 😮

boreal dome
#

On stable?

narrow tiger
#

well... RUSTC_BOOTSTRAP=1

#

also it's in the unstable book

#

so it's not on stable

#

🤔

#

Ok nvm it's just another RUSTC_BOOSTRAP

#

I mean it's less "generic" because it's specific for cargo

#

I'll put this on my TODO and see if I can get a stabilization PR

#

seems feature complete

boreal dome
narrow tiger
#

yes I was just looking at the unstable book and the related issues

#

but host-config requires target-applies-to-host

gaunt mica
#

I'd like to compile my program with +avx,+avx512f but setting RUSTFLAGS=-C target-feature=+avx,+avx512f results in a SIGILL because it compiles the build script for a dependency with AVX-512, which my host doesn't have

boreal dome
#

If you invoke cargo with --target <triple>, then the RUSTFLAGS won't be applied to build scripts or proc macros.