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

feat: setup bootstrap and ci #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: setup bootstrap and ci #3

wants to merge 5 commits into from

Conversation

Wybxc
Copy link

@Wybxc Wybxc commented Sep 19, 2024

This pull request sets up the bootstrap process and CI for the C codegen backend.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

I left some minor nits. I also have a question for this backend: is there a reason why you need to reinvent a bootstrap instead of forking the rust repo then adding additional logic as necessary?

EDIT: to clarify, it's entirely possible that you have very good reasons or run into difficult limitations for doing so. I'm asking because using Yet Another Bootstrap makes (1) upstreaming the backend very very difficult and (2) makes it more difficult for other rustc contributors who wants to make changes to this backend because they have to deal with the intricacies of Yet Another Build System.

bootstrap/.gitignore Show resolved Hide resolved
bootstrap/src/clean.rs Outdated Show resolved Hide resolved
bootstrap/src/fmt.rs Outdated Show resolved Hide resolved
bootstrap/src/test.rs Show resolved Hide resolved
bootstrap/src/test.rs Outdated Show resolved Hide resolved
bootstrap/src/test.rs Outdated Show resolved Hide resolved
@Wybxc
Copy link
Author

Wybxc commented Sep 20, 2024

I left some minor nits. I also have a question for this backend: is there a reason why you need to reinvent a bootstrap instead of forking the rust repo then adding additional logic as necessary?我留下了一些小虱子。我对这个后端还有一个问题:是否有理由需要重新发明引导程序,而不是分叉rust存储库,然后根据需要添加额外的逻辑?

EDIT: to clarify, it's entirely possible that you have very good reasons or run into difficult limitations for doing so. I'm asking because using Yet Another Bootstrap makes (1) upstreaming the backend very very difficult and (2) makes it more difficult for other rustc contributors who wants to make changes to this backend because they have to deal with the intricacies of Yet Another Build System.编辑:澄清一下,您完全有可能有很好的理由或遇到困难的限制。我这么问是因为使用 Yet Another Bootstrap 会(1)使后端上游变得非常非常困难,并且(2)使其他想要更改此后端的 rustc 贡献者变得更加困难,因为他们必须处理 Yet Another 的复杂性构建系统。

In projects such as rustc_codegen_cranelift or rust_codegen_gcc, there exists a component referred to as the build_system, which serves a similar function to what is termed "bootstrap" in this context. It is important to distinguish this from the bootstrap process of the Rust compiler itself. In this instance, we assume the presence of an operational Rust compiler, and we merely encapsulate some command-line invocations to rustc, making rustc_codegen_c the default code generation option.

@Wybxc
Copy link
Author

Wybxc commented Sep 20, 2024

Refer to #2 (comment)

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

I think this looks pretty good overall. Please just make sure absolute paths are used everywhere, otherwise it looks like a lot of things will break when running from a different directory.

Aside from that, a few other comments but I don't see any big issues.

bootstrap/.gitignore Show resolved Hide resolved
run: |
rustup update nightly --no-self-update
rustup default nightly
rustup component add clippy
run: rustup show
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to use rustup toolchain install to make sure the version from the toolchain file is used, since rust-lang/rustup#3983

Copy link
Author

Choose a reason for hiding this comment

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

This feature is not yet available in the release version of rustup. Perhaps we can wait for the next release of rustup before switching the approach here.


impl CleanCommand {
pub fn run(&self, manifest: &Manifest) {
let _ = std::fs::remove_dir_all("crates/target");
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 an absolute path presumably based on location information in Manifest, so running from a different location doesn't remove the wrong thing.

Comment on lines +18 to +33
.args(["--manifest-path", "bootstrap/Cargo.toml"]),
);
self.perform(
Command::new("cargo")
.arg("fmt")
.args(["--manifest-path", "crates/Cargo.toml"])
.arg("--all"),
);
for file in glob("example/**/*.rs").unwrap() {
self.perform(
Command::new("rustfmt")
.args(["--edition", "2021"])
.arg(file.unwrap()),
);
}
for file in glob("tests/**/*.rs").unwrap() {
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 use absolute paths too.

}
}

pub fn perform(&self, command: &mut Command) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: perform and run should probably get different names since it isn't very obvious what the difference is. Or ideally, just put this into a trait so all steps are required to use the same interface.

Nonblocker though, this can be changed later.

Comment on lines +23 to +25
/// debug mode
#[arg(short, long)]
pub debug: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be called verbose based on how it is use. debug sounds like it would be the opposite of release.

pub out_dir: PathBuf,
}

impl Manifest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Double check that absolute paths are used in this block

Comment on lines +116 to +121
"FileCheck",
"FileCheck-14",
"FileCheck-15",
"FileCheck-16",
"FileCheck-17",
"FileCheck-18",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you probably want to reverse the order so newer filecheck versions get preferred?

Copy link
Author

Choose a reason for hiding this comment

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

One additional question: Should we prefer FileCheck or FileCheck-18?

Copy link
Member

Choose a reason for hiding this comment

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

If you can be specific, then pinning it to a specific FileCheck version seems nicer for reproducibility (and bumps to which FileCheck version is used then becomes explicit)

@Wybxc
Copy link
Author

Wybxc commented Sep 22, 2024

I think this looks pretty good overall. Please just make sure absolute paths are used everywhere, otherwise it looks like a lot of things will break when running from a different directory.

Aside from that, a few other comments but I don't see any big issues.

The use cases for bootstrap are typically highly specific to the project structure, making execution in alternative directories impractical. Additionally, the brevity of the ./y command serves as a clear reminder of the current working directory.

As far as I am aware, rustc_codegen_gcc also utilizes relative paths:
https://github.com/rust-lang/rustc_codegen_gcc/blob/3018d9dc8fc2fe19a0e7366166ceb6829d1b273d/build_system/src/clean.rs#L72
https://github.com/rust-lang/rustc_codegen_gcc/blob/3018d9dc8fc2fe19a0e7366166ceb6829d1b273d/build_system/src/main.rs#L16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants