Skip to content

feat: Implementation and tests 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

Open
wants to merge 4 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

@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?

@namanlp namanlp force-pushed the multiple-build-scripts-2 branch 2 times, most recently from 2042b1c to 96ca257 Compare June 26, 2025 19:53
@namanlp namanlp force-pushed the multiple-build-scripts-2 branch 4 times, most recently from 4b8bdec to 934c3b2 Compare June 27, 2025 20:10
@namanlp
Copy link
Contributor Author

namanlp commented Jun 30, 2025

I am marking this PR Ready for Review. Please do let me know if I have missed anything

@namanlp namanlp marked this pull request as ready for review June 30, 2025 19:44
@rustbot
Copy link
Collaborator

rustbot commented Jun 30, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 30, 2025
@namanlp namanlp changed the title WIP: Implementation for multiple build scripts feat: Implementation and tests for multiple-build-scripts Jun 30, 2025
@namanlp
Copy link
Contributor Author

namanlp commented Jun 30, 2025

r? @epage

@rustbot rustbot assigned epage and unassigned weihanglo Jun 30, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have multiple build scripts working, we need to update

fn rerun_untracks_other_files() {

Comment on lines +346 to 352
if let Some(meta_vec) = script_metas {
for meta in meta_vec {
if let Some(env) = self.extra_env.get(meta) {
for (k, v) in env {
cmd.env(k, v);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What should happen when two build scripts output conflicting information?

Whichever route we go, we should have a test for it. In fact, environment variable tests are probably the best way to test multiple build scripts ran.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While performing experiments, I don't know why, last one specified doesn't win. Rather, the lexicographically smallest build script wins.

For example, I have 2 build scripts, build1.rs and build2.rs, building files a.cpp and b.cpp (using cc), such that both a.cpp and b.cpp has functions foo, but foo is different in these files.

So, if we run it, no matter the order in Cargo.toml, build1.rs always wins, and hence, a.cpp always wins. Also, changing a.cpp to d.cpp doesn't change anything, but if we change build1.rs to build3.rs, build2.rs wins.

And it is deterministic, and not random, I have tested it like 50 times on my system ( I made a little bash script that cargo clean and then cargo run ). I am not completely sure why though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, it is exactly opposite in environment variables. The lexicographically largest script, ie, build3.rs always wins.

@epage
Copy link
Contributor

epage commented Jul 1, 2025

Also, another case we need to handle is OUT_DIR. That could be a follow up PR.

@namanlp namanlp force-pushed the multiple-build-scripts-2 branch from 934c3b2 to d6e4d74 Compare July 3, 2025 21:29
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants