Skip to content

WIP: Implementation for multiple build scripts #15704

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

namanlp
Copy link
Contributor

@namanlp namanlp commented Jun 25, 2025

Hi Everyone!

This is PR for the implementation of the first milestone of GSoC Project : Build Script Delegation

This will provide actual implementation for #15630

What does this PR try to resolve?

Now, multiple build scripts are parsed, this PR aims to implement the functioning the feature. This PR will allow users to 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 via cargo-features in Cargo.toml. So, you have to add

cargo-features = ["multiple-build-scripts"]

Preferably on the top of the Cargo.toml and use nightly toolchain to use the feature

This PR is WIP and not ready for review yet!

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-build-scripts Area: build.rs scripts A-dep-info Area: dep-info, .d files Command-run Command-test labels Jun 25, 2025
@epage
Copy link
Contributor

epage commented Jun 26, 2025

This is PR for the manifest parsing of the first milestone of GSoC Project : Build Script Delegation

Bad copy/paste?

pub fn find_build_script_metadata(&self, unit: &Unit) -> Option<UnitHash> {
let script_unit = self.find_build_script_unit(unit)?;
Some(self.get_run_build_script_metadata(&script_unit))
pub fn find_build_script_metadata(&self, unit: &Unit) -> Option<Vec<UnitHash>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_build_script_metadata -> find_build_script_metadatas to express through the name that this is plural

@@ -45,7 +45,7 @@ pub struct Doctest {
/// The script metadata, if this unit's package has a build script.
///
/// This is used for indexing [`Compilation::extra_env`].
pub script_meta: Option<UnitHash>,
pub scripts_meta: Option<Vec<UnitHash>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always a weird question on whether to pluralize the first part or second. I lean towards the second

@@ -61,7 +61,7 @@ pub struct UnitOutput {
/// The script metadata, if this unit's package has a build script.
///
/// This is used for indexing [`Compilation::extra_env`].
pub script_meta: Option<UnitHash>,
pub script_meta: Option<Vec<UnitHash>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also pluralize this?

}

/// Returns a [`ProcessBuilder`] for running `rustdoc`.
pub fn rustdoc_process(
&self,
unit: &Unit,
script_meta: Option<UnitHash>,
script_meta: &Option<Vec<UnitHash>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be switched to Option<&Vec<UnitHash>>, (accessed via Option::as_ref) or Option<&[UnitHash]>, (accessed via Option::as_deref)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True for all other &Options

Comment on lines +428 to 446
pub fn find_build_script_units(&self, unit: &Unit) -> Option<Vec<Unit>> {
if unit.mode.is_run_custom_build() {
return Some(unit.clone());
return Some(vec![unit.clone()]);
}
self.bcx.unit_graph[unit]

let build_script_units: Vec<Unit> = self.bcx.unit_graph[unit]
.iter()
.find(|unit_dep| {
.filter(|unit_dep| {
unit_dep.unit.mode.is_run_custom_build()
&& unit_dep.unit.pkg.package_id() == unit.pkg.package_id()
})
.map(|unit_dep| unit_dep.unit.clone())
.collect();
if build_script_units.is_empty() {
None
} else {
Some(build_script_units)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What order is this returning units? We should do it in a deterministic order, preferably one controlled by the user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this commit is just about changing types, we can always add this in a later commit

@namanlp namanlp force-pushed the multiple-build-scripts-2 branch from 66a7106 to 2042b1c Compare June 26, 2025 19:36
@namanlp namanlp force-pushed the multiple-build-scripts-2 branch from 2042b1c to 96ca257 Compare June 26, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-build-scripts Area: build.rs scripts A-dep-info Area: dep-info, .d files Command-run Command-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants