-
Notifications
You must be signed in to change notification settings - Fork 14k
Bootstrap config: libgccjit libs dir #149354
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
antoyo
wants to merge
6
commits into
rust-lang:main
Choose a base branch
from
antoyo:bootstrap-config/libgccjit-libs-dir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3bcdbb1
Add libgccjit-libs-dir config
antoyo 6287804
Do not build or download libgccjit if using libgccjit-libs-dir
antoyo 2051784
Formatting
antoyo f61b743
Fix tidy
antoyo cb23f5d
Add new config in example
antoyo 1bf3007
Fix clippy warning
antoyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,11 @@ pub struct Gcc { | |
|
|
||
| #[derive(Clone)] | ||
| pub struct GccOutput { | ||
| pub libgccjit: PathBuf, | ||
| /// Path to a built or downloaded libgccjit. | ||
| /// Is None when setting libgccjit-libs-dir. | ||
| /// FIXME: it seems wrong to make this an Option. | ||
| /// Perhaps it should be a Vec so that we can install all libs from libgccjit-libs-dir? | ||
| pub libgccjit: Option<PathBuf>, | ||
| } | ||
|
|
||
| impl GccOutput { | ||
|
|
@@ -36,23 +40,55 @@ impl GccOutput { | |
| return; | ||
| } | ||
|
|
||
| // At build time, cg_gcc has to link to libgccjit.so (the unversioned symbol). | ||
| // However, at runtime, it will by default look for libgccjit.so.0. | ||
| // So when we install the built libgccjit.so file to the target `directory`, we add it there | ||
| // with the `.0` suffix. | ||
| let mut target_filename = self.libgccjit.file_name().unwrap().to_str().unwrap().to_string(); | ||
| target_filename.push_str(".0"); | ||
|
|
||
| // If we build libgccjit ourselves, then `self.libgccjit` can actually be a symlink. | ||
| // In that case, we have to resolve it first, otherwise we'd create a symlink to a symlink, | ||
| // which wouldn't work. | ||
| let actual_libgccjit_path = t!( | ||
| self.libgccjit.canonicalize(), | ||
| format!("Cannot find libgccjit at {}", self.libgccjit.display()) | ||
| ); | ||
| if let Some(ref path) = self.libgccjit { | ||
| // At build time, cg_gcc has to link to libgccjit.so (the unversioned symbol). | ||
| // However, at runtime, it will by default look for libgccjit.so.0. | ||
| // So when we install the built libgccjit.so file to the target `directory`, we add it there | ||
| // with the `.0` suffix. | ||
| let mut target_filename = path.file_name().unwrap().to_str().unwrap().to_string(); | ||
| target_filename.push_str(".0"); | ||
|
|
||
| // If we build libgccjit ourselves, then `self.libgccjit` can actually be a symlink. | ||
| // In that case, we have to resolve it first, otherwise we'd create a symlink to a symlink, | ||
| // which wouldn't work. | ||
| let actual_libgccjit_path = t!( | ||
| path.canonicalize(), | ||
| format!("Cannot find libgccjit at {}", path.display()) | ||
| ); | ||
|
|
||
| let dst = directory.join(&target_filename); | ||
| builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary); | ||
| } | ||
|
|
||
| if let Some(ref path) = builder.config.libgccjit_libs_dir { | ||
| let host_target = builder.config.host_target.triple; | ||
|
|
||
| let source = path.join(host_target); | ||
| let dst = directory; | ||
|
|
||
| let targets = builder.config.targets.iter() | ||
| .map(|target| target.triple) | ||
| .chain(std::iter::once(host_target)); | ||
|
|
||
| let target_filename = "libgccjit.so.0"; | ||
| for target in targets { | ||
| let source = source.join(target).join(target_filename); | ||
| // To support symlinks in libgccjit-libs-dir, we have to resolve it first, | ||
| // otherwise we'd create a symlink to a symlink, which wouldn't work. | ||
| let actual_libgccjit_path = t!( | ||
| source.canonicalize(), | ||
| format!("Cannot find libgccjit at {}", source.display()) | ||
| ); | ||
| let target_dir = dst.join(target); | ||
| t!( | ||
| std::fs::create_dir_all(&target_dir), | ||
| format!("Cannot create target dir {} for libgccjit", target_dir.display()) | ||
| ); | ||
| let dst = target_dir.join(&target_filename); | ||
| builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary); | ||
| } | ||
| } | ||
|
|
||
| let dst = directory.join(target_filename); | ||
| builder.copy_link(&actual_libgccjit_path, &dst, FileType::NativeLibrary); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -75,7 +111,8 @@ impl Step for Gcc { | |
|
|
||
| // If GCC has already been built, we avoid building it again. | ||
| let metadata = match get_gcc_build_status(builder, target) { | ||
| GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path }, | ||
| GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: Some(path) }, | ||
| GccBuildStatus::InLibsDir => return GccOutput { libgccjit: None }, | ||
| GccBuildStatus::ShouldBuild(m) => m, | ||
| }; | ||
|
|
||
|
|
@@ -85,14 +122,14 @@ impl Step for Gcc { | |
|
|
||
| let libgccjit_path = libgccjit_built_path(&metadata.install_dir); | ||
| if builder.config.dry_run() { | ||
| return GccOutput { libgccjit: libgccjit_path }; | ||
| return GccOutput { libgccjit: Some(libgccjit_path) }; | ||
| } | ||
|
|
||
| build_gcc(&metadata, builder, target); | ||
|
|
||
| t!(metadata.stamp.write()); | ||
|
|
||
| GccOutput { libgccjit: libgccjit_path } | ||
| GccOutput { libgccjit: Some(libgccjit_path) } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -106,6 +143,7 @@ pub struct Meta { | |
| pub enum GccBuildStatus { | ||
| /// libgccjit is already built at this path | ||
| AlreadyBuilt(PathBuf), | ||
| InLibsDir, | ||
| ShouldBuild(Meta), | ||
| } | ||
|
|
||
|
|
@@ -170,6 +208,11 @@ fn try_download_gcc(_builder: &Builder<'_>, _target: TargetSelection) -> Option< | |
| /// It's used to avoid busting caches during x.py check -- if we've already built | ||
| /// GCC, it's fine for us to not try to avoid doing so. | ||
| pub fn get_gcc_build_status(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus { | ||
| if matches!(builder.config.gcc_ci_mode, crate::core::config::GccCiMode::CopyFromLibsDir) { | ||
| // TODO: check if this is OK. | ||
|
||
| return GccBuildStatus::InLibsDir; | ||
| } | ||
|
|
||
| if let Some(path) = try_download_gcc(builder, target) { | ||
| return GccBuildStatus::AlreadyBuilt(path); | ||
| } | ||
|
|
@@ -293,7 +336,9 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) { | |
| /// Configures a Cargo invocation so that it can build the GCC codegen backend. | ||
| pub fn add_cg_gcc_cargo_flags(cargo: &mut Cargo, gcc: &GccOutput) { | ||
| // Add the path to libgccjit.so to the linker search paths. | ||
| cargo.rustflag(&format!("-L{}", gcc.libgccjit.parent().unwrap().to_str().unwrap())); | ||
| if let Some(ref path) = gcc.libgccjit { | ||
| cargo.rustflag(&format!("-L{}", path.parent().unwrap().to_str().unwrap())); | ||
| } | ||
| } | ||
|
|
||
| /// The absolute path to the downloaded GCC artifacts. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Kobzol: What are your thoughts about this?