Skip to content
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

wrong target_os? #1627

Closed
1 of 11 tasks
ibigbug opened this issue Feb 12, 2025 · 6 comments
Closed
1 of 11 tasks

wrong target_os? #1627

ibigbug opened this issue Feb 12, 2025 · 6 comments

Comments

@ibigbug
Copy link

ibigbug commented Feb 12, 2025

Checklist

Describe your issue

have a build.rs in an empty crate

fn main(){
#[cfg(target_os="linux")]
println!("cargo:warning=linux");
#[cfg(target_os = "freebsd")]
println!("cargo:warning=freebsd");
}

and run cross build --target x86_64-unknown-freebsd

it should print "freebsd"

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.5 (107433f 2025-02-06) [cross] note: Falling back to cargo on the host. cargo 1.83.0 (5ffbef321 2024-10-29)

Example

No response

Additional information / notes

No response

@Emilgardis
Copy link
Member

why would a cross build run the executable?

Is this a buildscript? buildscripts are ran as the host, so when a buildscript is ran target_os=host_os

@ibigbug
Copy link
Author

ibigbug commented Feb 12, 2025

sorry i wasn't clear it was a build script(updated desc)

buildscripts are ran as the host, so when a buildscript is ran target_os=host_os

I see. that makes so much sense.

I was trying to build this https://github.com/LeoBorai/network-interface/blob/main/build.rs#L5

do you think it's possible to cross it ? given the build script was created that way

@ibigbug
Copy link
Author

ibigbug commented Feb 12, 2025

buildscripts are ran as the host

so this is actually the cargo behaviour?

@ibigbug
Copy link
Author

ibigbug commented Feb 12, 2025

rust-lang/cargo#13277 found it

@Emilgardis
Copy link
Member

yes it's possible, they are doing a big mistake in the buildscript, it should be gated by runtime env args, not cfg.

See https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts

@Emilgardis
Copy link
Member

closing this issue as it's nothing we can resolve. The build script needs to be fixed

@Emilgardis Emilgardis closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants