-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[WIP] feat: Multiple build scripts #15630
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
base: master
Are you sure you want to change the base?
Conversation
Feel free to rebase on |
60fe887
to
f6bebc3
Compare
b7a6036
to
1d18b6b
Compare
src/cargo/core/features.rs
Outdated
@@ -1361,6 +1362,7 @@ impl CliUnstable { | |||
"msrv-policy" => self.msrv_policy = parse_empty(k, v)?, | |||
// can also be set in .cargo/config or with and ENV | |||
"mtime-on-use" => self.mtime_on_use = parse_empty(k, v)?, | |||
"multiple-build-scripts" => self.multiple_build_scripts = parse_empty(k, v)?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit should also add a section for this to our unstable docs. There isn't much to say but we should add more to it as features get implemented.
TomlPackageBuild::MultipleScript(_scripts) => { | ||
unimplemented!("Multiple Build Scripts feature is not implemented yet!") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a commit before this one, we should update normalized_build
to return Result<Option<&Vec<String>>, UnresolvedError>
to avoid this unimplemented!
match &package.build { | ||
Some(TomlPackageBuild::SingleScript(path)) => { | ||
let path = paths::normalize_path(Path::new(path)); | ||
let included = packaged_files.contains(&path); | ||
let build = if included { | ||
let path = path | ||
.into_os_string() | ||
.into_string() | ||
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?; | ||
let path = crate::util::toml::normalize_path_string_sep(path); | ||
TomlPackageBuild::SingleScript(path) | ||
} else { | ||
gctx.shell().warn(format!( | ||
"ignoring `package.build` as `{}` is not included in the published package", | ||
path.display() | ||
))?; | ||
TomlPackageBuild::Auto(false) | ||
}; | ||
package.build = Some(build); | ||
} | ||
Some(TomlPackageBuild::MultipleScript(_scripts)) => { | ||
if gctx.cli_unstable().multiple_build_scripts { | ||
unimplemented!("Multiple build script is not implemented yet!"); | ||
} else { | ||
bail!("`build = […]` requires `-Z multiple-build-scripts`"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend unifying this code so there is a single code path for single or multiple scripts.
Maybe something like https://doc.rust-lang.org/std/option/enum.Option.html#method.as_slice could help
src/cargo/util/toml/mod.rs
Outdated
let multiple_build_scripts = gctx.cli_unstable().multiple_build_scripts; | ||
let build = if is_embedded { | ||
Some(TomlPackageBuild::Auto(false)) | ||
} else { | ||
targets::normalize_build(original_package.build.as_ref(), package_root) | ||
targets::normalize_build( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the hackiest hack is the best hack"
or
"when implementing short-lived or hacky code, be as surgical as possible"
I'd recommend we do the unstable check here, rather than updating normalize_build
s API to take in a parameter related to this
src/cargo/core/features.rs
Outdated
@@ -840,6 +840,7 @@ unstable_cli_options!( | |||
minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"), | |||
msrv_policy: bool = ("Enable rust-version aware policy within cargo"), | |||
mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"), | |||
multiple_build_scripts: bool = ("Enables the use of multiple build scripts"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overlooked this before, this was implemented as a -Z
when this needs to be a cargo_features
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, replaced it with cargo_features
src/cargo/util/toml/mod.rs
Outdated
// Validates if build script file exists. If not, warn and ignore. | ||
if let Some(TomlPackageBuild::SingleScript(path)) = &package.build { | ||
let path = Path::new(path).to_path_buf(); | ||
let included = packaged_files.map(|i| i.contains(&path)).unwrap_or(true); | ||
let build = if included { | ||
let path = path | ||
.into_os_string() | ||
.into_string() | ||
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?; | ||
let path = normalize_path_string_sep(path); | ||
TomlPackageBuild::SingleScript(path) | ||
} else { | ||
ws.gctx().shell().warn(format!( | ||
"ignoring `package.build` as `{}` is not included in the published package", | ||
path.display() | ||
))?; | ||
TomlPackageBuild::Auto(false) | ||
}; | ||
package.build = Some(build); | ||
match &package.build { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto what I said with vendor
} | ||
Some(TomlPackageBuild::MultipleScript(_scripts)) => { | ||
if multiple_build_scripts { | ||
unimplemented!("Multiple Build Scripts feature is not implemented yet!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go ahead and do this in this commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'd like to see runtime errors, rather than panics for when we cut users off from this feature.
0321144
to
6de78d5
Compare
6de78d5
to
158dd35
Compare
Hi Everyone!
This is PR for first milestone of GSoC Project : Build Script Delegation
What does this PR try to resolve?
Currently, just a single build script is allowed for each package. This PR will allow users to create and use multiple build scripts, and is backward compatible with single script as well as boolean values.
Motivation : This will help users to maintain separate smaller and cleaner build scripts instead of one large build script. This is also necessary for build script delegation.
How to test and review this PR?
There is a feature gate
multiple-build-scripts
that can be passed with-Z
in cargo.It is not ready for review yet