-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Reduce the need for users to write build scripts #14948
Comments
I would draw a distinction between main binary build scripts (e.g. the executable or cdylib) and libraries. I think a build scripts for an executable is far more tolerable than for libraries. They're in direct control of the crate author and don't have any other users. Also a single top-level build script is going to have negligible impact on build times for all but the smallest projects. Which is not to say reducing the need for them is not important too, just that reducing the need for library build scripts will likely have the far bigger impact. |
This is not about trying to remove all build scripts but finding patterns in the community and providing a solution to avoid writing one yourself. In some cases, this will be using an artifact dependency as your build script. This is a general solution that helps libs and bins. And the benefits extend to bins. For smaller projects it democratizes the benefits of build scripts by making it easier to discover what you can do, easier to implement, and with fewer bugs. For larger projects with multiple bins, it makes reuse easier, reduces build times, and makes it easier to audit your own code base. Yes, libs will get more benefits as we prioritize solutions to implement but understanding and tracking the needs of bins takes little away from that but instead gives a better understanding for designing soluations. |
I don't know if this is important enough, but I also have a small use-case: I integrate a version string from an environment variable into my program during compile time. A natural way to do this would be the So I am forced to use a build script with the |
|
Oh that works! 😊 I don't know what went wrong the last time I tested it, sorry for the confusion. |
Cargo might not fully track its own env variables which would be a bug. iirc |
Did you mean |
Can we add "cfg aliases" to this list (i.e. what is implemented using a build script by the https://docs.rs/cfg_aliases/latest/cfg_aliases/ crate)? Winit is a prominent crate that depends on this Use cases where this is commonly comes up are where there is functionality that works on N of M platforms (e.g. 3 of 6), that you also want to be controllable with a feature flag (users may or may not want the function), and that you want to be disabled on platforms where it doesn't work even when the feature is enabled (as otherwise it becomes burdensome for users to set platform-specific features (where this is even possible)). To give an entirely concrete example. In blitz-shell we use muda for implementing system menus on windows/macos/linux(desktop), but this functionality isn't available and doesn't make sense on android/ios/web. We also wish to make it optional on platforms that do support it. So we need a feature flag AND platform-specific It would be nice if we could define aliases (either in |
@nicoburns I've added |
I feel like the use cases given might have some overlap with global, mutually exclusive features and I wonder if there is a way to fit a higher level construct into that. |
Another use case we have is to record the I mean, there's other ways as well like linking in function to get info, but stamping this in the executable might be useful to external tools as well. Just some thoughts. |
The
As for PE/COFF executables, it looks like the PDB debuginfo file will contain the rustc string. At least https://rust.godbolt.org/z/3zxrKehsK shows the |
Interesting. I ran As for PE/COFF, I expected this was in the
|
Like RUSTFLAGS, build scripts are an important escape hatch. Like RUSTFLAGS (#12739), we should find replacements for common uses of build scripts so people don't have to reach to this escape hatch so often
Reducing build scripts would
Uses of build scripts
#[cfg(accessible(::path::to::thing))]
rust#64797#[cfg(version(..))]
rust#64796cfg
values available at runtime (e.g. in--bugreport
,--version
, or crash reports, or for tests building examples)cfg_value!
,cfg_values!
,try_cfg_value!
,try_cfg_values!
(see also mutually exclusive features)TARGET
available at runtime (e.g.--version
, building examples in tests)package.rs
) #12552-sys
crates?The text was updated successfully, but these errors were encountered: