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

Add possibility to exclude binaries from being built on specific platforms #3138

Closed
philippkeller opened this issue Sep 30, 2016 · 4 comments
Labels
A-manifest Area: Cargo.toml issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@philippkeller
Copy link

philippkeller commented Sep 30, 2016

I have src/bin/linux-only.rs which does some things which work on Linux only (e.g. libc bindings which only exist on Linux). I want to exclude that file from being built on OS X.

Could you add a way to exclude those, e.g.

[package(target_os=macos)]
exclude = ["src/bin/linux-only.rs"]

or (and that's probably the better way as it doesn't need new syntax): just remove the error error: main function not found when there's a #![cfg(target_os = "linux")] at the top of src/bin/linux-only.rs

Disclaimer: I'm fairly new to rust so maybe I'm doing something wrong. I read through the Cargo.toml docs and didn't find a way to make this work, I also did not get a satisfying answer on this SO post.

@alexcrichton
Copy link
Member

Thanks for the report! Yeah in Cargo right now this isn't too easy, but you can work around this with #[cfg] where on the non-relevant platforms it's just an empty fn main() {} with maybe a println! diagnostic explaining why.

@philippkeller
Copy link
Author

@alexcrichton that's what I'm currently doing. But it needs a #[cfg] attribute above every block (including use, structs, c bindings, etc. So I end up with 10-20 of these attributes which is cluttering the code. Is there a better way to do that?

@philippkeller
Copy link
Author

found a workoround via a build.sh script that generates separate Cargo.toml files for linux and osx, which leaves out rs files with the #![cfg(target_os = "...")] which doesn't match the current architecture.

philippkeller pushed a commit to philippkeller/apue-rust that referenced this issue Oct 1, 2016
philippkeller pushed a commit to philippkeller/apue-rust that referenced this issue Oct 1, 2016
@carols10cents carols10cents added A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Sep 27, 2017
@ehuss ehuss added A-manifest Area: Cargo.toml issues and removed A-configuration Area: cargo config files and env vars labels Aug 11, 2019
@weihanglo
Copy link
Member

Hey there. I am going to close this since more discussions happens in #9208 for the same issue. Thank you!

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-manifest Area: Cargo.toml issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

5 participants