Skip to content

introduce a linux android macro - #10432

Closed
sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:android-linux-macro
Closed

introduce a linux android macro#10432
sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:android-linux-macro

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

No description provided.

@ChrisDryden

ChrisDryden commented Jan 22, 2026

Copy link
Copy Markdown
Collaborator

I'm not able to identify why this doesn't work in the CI, did you investigate using cfg-aliases? #9559

@ChrisDryden

Copy link
Copy Markdown
Collaborator

Did some further research, its failing because the #[cfg(...)] attribute evaluates based on the host machine (where the build script runs), not the target machine.

This should work:

  if let Ok(target_os) = env::var("CARGO_CFG_TARGET_OS") {
      if target_os == "linux" || target_os == "android" {
          println!("cargo:rustc-cfg=linux_android");
      }
  }

I would love to do something similar for all of the BSD os's, it would make stty much cleaner and easier to read

@ChrisDryden

Copy link
Copy Markdown
Collaborator

Actually two issues here, the cross compilation and that this will only set that config for the parent crate and you would need this in a build.rs for every crate to do this. How about adding this to the Cargo.toml instead?

[target.'cfg(any(target_os = "linux", target_os = "android"))']
rustflags = ["--cfg", "linux_android"]

@ChrisDryden

Copy link
Copy Markdown
Collaborator

Actually that Cargo.toml rustflags is not ideal either since it wont work for anyone that wants to use any of the utilities as a dependency. Not really any great options here.

@sylvestre

Copy link
Copy Markdown
Contributor Author

probably why we haven't done it before :)

@oech3

oech3 commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

cfg-aliases is a dep of nix. No reason to avoid it (if works).

@xtqqczze

Copy link
Copy Markdown
Contributor

I know the name linux_android matches that in nix/nix-rust but I think it's a little unclear.

@oech3

oech3 commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

linux_kernel?

@xtqqczze

Copy link
Copy Markdown
Contributor

linux_kernel?

That's what bytecodealliance/rustix uses and much clearer.

@xtqqczze

Copy link
Copy Markdown
Contributor

Other suggestions, linux-targets, linux-all, linux-abi or simplylinux?

@xtqqczze

Copy link
Copy Markdown
Contributor

linux_kernel?

That's what bytecodealliance/rustix uses and much clearer.

Might be worth considering that Android might not always use a linux kernel. For example, a future release of Android might be based on starnix which uses fuchsia.

So linux-abi might be the most technically correct option.

@xtqqczze

xtqqczze commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

I'm leaning toward linux for simplicity and to align with the approach for bsd in #10443

@sylvestre sylvestre closed this Jun 7, 2026
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

Successfully merging this pull request may close these issues.

4 participants