-
Notifications
You must be signed in to change notification settings - Fork 481
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
Incorrect backend selection for non-standard targets #515
Comments
Not an issue in this crate - it has to be fixed with / in the custom build tooling that does not signal Also cross compiling works with no issue and the current behaviour is correct vs incorrectly assuming custom targets. This is a duplicate: I wonder which build tooling is being used that would not be able to set |
Looking at your repo's I'm assuming you are using a Makefile ? You would need to add Or in-line it in before the cargo command wrapped in the Makefile. Or are you using cross with Cross.toml ? https://github.com/cross-rs/cross#passing-environment-variables-into-the-build-environment There is passthrough option which people usually use with Would like to offer more help but dunno what custom build tooling is used. |
So there are two things happening here: @ryankurte is pointing out that build.rs will not see RUSTFLAGS when cross-compiling; this is correct. However, as @pinkforest notes, this has not been a problem for known targets, and that's because the cfg settings in RUSTFLAGS take priority over the ones from build.rs.* (If curve25519-dalek's build.rs did anything with the cfg options other than pass them down to the compiler, this would be a problem even for built-in targets.) So what is the problem? * Here's a test case; compare |
It seems like we've had enough issues around this we should just pick a default for unknown platforms (and possibly print a warning?) |
i am pretty sure this is actually because when cross compiling the flag is always ignored but i have also confirmed that this occurs whether
so if you don't get it propagated you panic because of missing backend selection, and if you do manage to set it you panic because of the unwrap on failed detection. @pinkforest nothing custom in the build, repro here with
a default is a great idea! but even when you get a warning the current mechanisms for backend selection do not work as intended or documented which seems worth a fix?
|
Please use existing issue: determine function will not run if rustc would see Having a default target for custom targets has issues and I've outlined them in the existing issue above. I'll comment on the existing issue - this may be a rustc bug with custom targets. |
could very well be, there seem to be a lot of assumptions around about custom targets and target naming ^_^ |
Problem is if we now make default curve25519_dalek_bits default as 32 because selecting it does not work. Then people also will have problems selecting backend so really need to get to bottom of this. Another way to address this could be to register these custom targets in platforms crate if they are widely used. |
What if we expose an environment variable for building for custom targets to set these ? This would work/around the rustc issue not setting cfg correctly - but it will be in addition to existing cfg flags. |
yeah if there's a warning / prompt / documentation about setting backends i think you should probably, be able to set backends.
i am not sure i understand the opposition to fixing the incorrect behaviour of build.rs as i proposed, which would make the existing configuration mechanisms work as documented? |
I am trying to get to bottom of this since this also means people are not able to set these configuration settings. It means nobody is being able to set backend either which is a big issue beyond this. build.rs works fine otherwise - the issue is with cargo / rustc - we are effectively work/arounding over existing bug there. |
This is not the same issue as #511. The problem here is that using Cargo and using RUSTFLAGS cross-compiling for an unsupported platform will fail, because build.rs has an explicit panic in it. EDIT: (softening) My impression of #511 is a problem with "build systems that don't support build.rs setting cfg flags" |
It doesn't have that panic anymore - please use the main branch version. For cross did you use the Cross.toml to passthrough RUSTFLAGS ? I have no idea what is used for cross other than either cross or --target (works out of the box with standard targets) We have two issues - 1) environment issues where people don't passthrough RUSTFLAGS and 2) custom targets #511 |
@ryankurte Maybe that's enough to fix your issue? You're just using Cargo, right? |
This wouldn't since using custom target involves a bug in rustc / cargo where rustc does not set cfg correctly it seems. |
no, this is still broken because of the
yes, per my first post, manual backend selection for foreign targets is always ignored, which can be fixed by correctly using
it may be a bug where |
Using environment variables is not a standard way to configure builds in Rust. Standard way is to use cfg - there is nothing incorrect about it. We will allow extra environment variables but cfg will take priority. |
https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags
|
Build target cfg flags are not the same as curve25519_dalek cfg flags we've specified. cfg curve25519_dalek_bits and backend flags work correctly in standard targets with this build.rs just fine. |
you can test this by patching out diff --git a/build.rs b/build.rs
index a4c6b3e..6944276 100644
--- a/build.rs
+++ b/build.rs
@@ -18,7 +18,7 @@ fn main() {
let curve25519_dalek_bits = DalekBits::Dalek64;
#[cfg(all(not(curve25519_dalek_bits = "64"), not(curve25519_dalek_bits = "32")))]
- let curve25519_dalek_bits = deterministic::determine_curve25519_dalek_bits();
+ let curve25519_dalek_bits = panic!("whoops");
match curve25519_dalek_bits {
DalekBits::Dalek64 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"64\""), if the overrides were working for foreign in-tree targets this should not be used or executed, and compilation with |
The overrides work with my cargo / rustc - by deriving Debug to DalekBits: #[cfg(curve25519_dalek_bits = "32")]
let curve25519_dalek_bits = DalekBits::Dalek32;
#[cfg(curve25519_dalek_bits = "64")]
let curve25519_dalek_bits = DalekBits::Dalek64;
panic!("{}", curve25519_dalek_bits); $ env RUSTFLAGS='--cfg curve25519_dalek_bits="32"' cargo build
Setting to 64 gives me Dalek64 as expected - it doesn't matter if I put the panic after deterministic. This is on otherwise 64bit What is the cargo / rustc version you are using ? I'm using various and the behaviour is same. |
you seem to be compiling natively there, where |
$ env RUSTFLAGS='--cfg curve25519_dalek_bits="64"' cargo build --target wasm32-wasi
This is incorrect indeed - I thought I had this tested with wasm32-u-u sigh. Now let's see how we address this - as we need to address those configuration failures as well for custom targets. |
the fix i proposed in the first post works for in-tree and custom foreign targets |
Yeah we'll use environment variable if the cfg is not present but we'll use curve25519_dalek_ env outside cargo_cfg Need to check if the backend via EDIT: Oh yeah we can use CARGO_CFG_ indeed 👍 |
@ryankurte See #516 - I've added you as Co-authored-by given your fix |
hi folks,
we're compiling for a non-standard (ie. out-of-tree) target which means target detection doesn't work, and setting
'--cfg=curve25519_dalek_bits="32"'
per the docs (via the environment or.cargo/config
) does not have any effect, resulting in the error:digging into the
build.rs
script it appears y'all are usingcfg
flags to switch features, however, when cross compiling these are not propagated to native components (ie. build scripts) at build time, only when they are executed (so in effect these are always ignored for foreign targets?).via https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags:
based on the intent here it appears this should instead be switching on environmental variables as these are passed when the build script is executed during compilation for the foreign target, so to have this behave as documented the fix would be something like:
happy to open a PR if y'all would be open to this fix?
The text was updated successfully, but these errors were encountered: