-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[bootstrap] Add support for building gcc and libgccjit #125419
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
Merged
+604
−42
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9028177
Add GCC submodule
GuillaumeGomez 30feef6
Add libgccjit dist generation
GuillaumeGomez 71fe248
Ignore gcc submodule for tidy checks
GuillaumeGomez eda4287
Add missing licenses for GCC
GuillaumeGomez 1fd148d
Rename `LICENSES/GPL-2.0.txt` into `LICENSES/GPL-2.0-only.txt`
GuillaumeGomez 3ba7992
Correctly generate stamp for gcc
GuillaumeGomez ca52d30
Remove `src/gcc` from `rustfmt` checks
GuillaumeGomez c53c397
Update GCC version
GuillaumeGomez f5abc42
Update code comments to mention GCC and not LLVM
GuillaumeGomez 6db83ef
Update to new bootstrap API
GuillaumeGomez 2c4aa29
Move HashStamp to helpers
GuillaumeGomez 9c16548
Clean code and move check for GCC backend build in `dist.rs` directly
GuillaumeGomez cbef544
Add `gcc` to the `build` commands list
GuillaumeGomez b10a38b
Update declared licenses in `REUSE.toml`
GuillaumeGomez 42d6f57
Make gcc submodule shallow
GuillaumeGomez 1b39b43
Make gcc `root` absolute
GuillaumeGomez 4e7808a
Update to new `Builder` API
GuillaumeGomez 2a2422c
Fix licensing information in REUSE.toml
Kobzol 103e040
Check if the `libgccjit.so.0` file exists before creating a symlink t…
GuillaumeGomez 6917514
Run `download_prerequisites` before running gcc `configure`
GuillaumeGomez e7fa03b
Remove gcc changes for dist build
GuillaumeGomez 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
GCC RUNTIME LIBRARY EXCEPTION | ||
|
||
Version 3.1, 31 March 2009 | ||
|
||
Copyright © 2009 Free Software Foundation, Inc. <https://fsf.org/> | ||
|
||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. | ||
|
||
This GCC Runtime Library Exception ("Exception") is an additional permission under section 7 of the GNU General Public License, version 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that bears a notice placed by the copyright holder of the file stating that the file is governed by GPLv3 along with this Exception. | ||
|
||
When you use GCC to compile a program, GCC may combine portions of certain GCC header files and runtime libraries with the compiled program. The purpose of this Exception is to allow compilation of non-GPL (including proprietary) programs to use, in this way, the header files and runtime libraries covered by this Exception. | ||
0. Definitions. | ||
|
||
A file is an "Independent Module" if it either requires the Runtime Library for execution after a Compilation Process, or makes use of an interface provided by the Runtime Library, but is not otherwise based on the Runtime Library. | ||
|
||
"GCC" means a version of the GNU Compiler Collection, with or without modifications, governed by version 3 (or a specified later version) of the GNU General Public License (GPL) with the option of using any subsequent versions published by the FSF. | ||
|
||
"GPL-compatible Software" is software whose conditions of propagation, modification and use would permit combination with GCC in accord with the license of GCC. | ||
|
||
"Target Code" refers to output from any compiler for a real or virtual target processor architecture, in executable form or suitable for input to an assembler, loader, linker and/or execution phase. Notwithstanding that, Target Code does not include data in any format that is used as a compiler intermediate representation, or used for producing a compiler intermediate representation. | ||
|
||
The "Compilation Process" transforms code entirely represented in non-intermediate languages designed for human-written code, and/or in Java Virtual Machine byte code, into Target Code. Thus, for example, use of source code generators and preprocessors need not be considered part of the Compilation Process, since the Compilation Process can be understood as starting with the output of the generators or preprocessors. | ||
|
||
A Compilation Process is "Eligible" if it is done using GCC, alone or with other GPL-compatible software, or if it is done without using any work based on GCC. For example, using non-GPL-compatible Software to optimize any GCC intermediate representations would not qualify as an Eligible Compilation Process. | ||
1. Grant of Additional Permission. | ||
|
||
You have permission to propagate a work of Target Code formed by combining the Runtime Library with Independent Modules, even if such propagation would otherwise violate the terms of GPLv3, provided that all Target Code was generated by Eligible Compilation Processes. You may then convey such a combination under terms of your choice, consistent with the licensing of the Independent Modules. | ||
2. No Weakening of GCC Copyleft. | ||
|
||
The availability of this Exception does not imply any general presumption that third-party software is unaffected by the copyleft requirements of the license of GCC. |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ISC License | ||
|
||
<copyright notice> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
//! Compilation of native dependencies like GCC. | ||
//! | ||
//! Native projects like GCC unfortunately aren't suited just yet for | ||
//! compilation in build scripts that Cargo has. This is because the | ||
//! compilation takes a *very* long time but also because we don't want to | ||
//! compile GCC 3 times as part of a normal bootstrap (we want it cached). | ||
//! | ||
//! GCC and compiler-rt are essentially just wired up to everything else to | ||
//! ensure that they're always in place if needed. | ||
|
||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::sync::OnceLock; | ||
|
||
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step}; | ||
use crate::core::config::TargetSelection; | ||
use crate::utils::exec::command; | ||
use crate::utils::helpers::{self, t, HashStamp}; | ||
use crate::{generate_smart_stamp_hash, Kind}; | ||
|
||
pub struct Meta { | ||
stamp: HashStamp, | ||
out_dir: PathBuf, | ||
install_dir: PathBuf, | ||
root: PathBuf, | ||
} | ||
|
||
pub enum GccBuildStatus { | ||
AlreadyBuilt, | ||
ShouldBuild(Meta), | ||
} | ||
|
||
/// This returns whether we've already previously built GCC. | ||
/// | ||
/// 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 prebuilt_gcc_config(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus { | ||
// Initialize the gcc submodule if not initialized already. | ||
builder.config.update_submodule("src/gcc"); | ||
|
||
// FIXME (GuillaumeGomez): To be done once gccjit has been built in the CI. | ||
// builder.config.maybe_download_ci_gcc(); | ||
|
||
let root = builder.src.join("src/gcc"); | ||
let out_dir = builder.gcc_out(target).join("build"); | ||
let install_dir = builder.gcc_out(target).join("install"); | ||
|
||
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new(); | ||
let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| { | ||
generate_smart_stamp_hash( | ||
builder, | ||
&builder.config.src.join("src/gcc"), | ||
builder.in_tree_gcc_info.sha().unwrap_or_default(), | ||
) | ||
}); | ||
|
||
let stamp = out_dir.join("gcc-finished-building"); | ||
let stamp = HashStamp::new(stamp, Some(smart_stamp_hash)); | ||
|
||
if stamp.is_done() { | ||
if stamp.hash.is_none() { | ||
builder.info( | ||
"Could not determine the GCC submodule commit hash. \ | ||
Assuming that an GCC rebuild is not necessary.", | ||
); | ||
builder.info(&format!( | ||
"To force GCC to rebuild, remove the file `{}`", | ||
stamp.path.display() | ||
)); | ||
} | ||
return GccBuildStatus::AlreadyBuilt; | ||
} | ||
|
||
GccBuildStatus::ShouldBuild(Meta { stamp, out_dir, install_dir, root }) | ||
} | ||
|
||
#[derive(Debug, Clone, Hash, PartialEq, Eq)] | ||
pub struct Gcc { | ||
pub target: TargetSelection, | ||
} | ||
|
||
impl Step for Gcc { | ||
type Output = bool; | ||
|
||
const ONLY_HOSTS: bool = true; | ||
|
||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { | ||
run.path("src/gcc").alias("gcc") | ||
} | ||
|
||
fn make_run(run: RunConfig<'_>) { | ||
run.builder.ensure(Gcc { target: run.target }); | ||
} | ||
|
||
/// Compile GCC for `target`. | ||
fn run(self, builder: &Builder<'_>) -> bool { | ||
let target = self.target; | ||
|
||
// If GCC has already been built, we avoid building it again. | ||
let Meta { stamp, out_dir, install_dir, root } = match prebuilt_gcc_config(builder, target) | ||
{ | ||
GccBuildStatus::AlreadyBuilt => return true, | ||
GccBuildStatus::ShouldBuild(m) => m, | ||
}; | ||
|
||
let _guard = builder.msg_unstaged(Kind::Build, "GCC", target); | ||
t!(stamp.remove()); | ||
let _time = helpers::timeit(builder); | ||
t!(fs::create_dir_all(&out_dir)); | ||
|
||
if builder.config.dry_run() { | ||
return true; | ||
} | ||
|
||
command(root.join("contrib/download_prerequisites")).current_dir(&root).run(builder); | ||
command(root.join("configure")) | ||
Kobzol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.current_dir(&out_dir) | ||
.arg("--enable-host-shared") | ||
.arg("--enable-languages=jit") | ||
.arg("--enable-checking=release") | ||
.arg("--disable-bootstrap") | ||
.arg("--disable-multilib") | ||
.arg(format!("--prefix={}", install_dir.display())) | ||
.run(builder); | ||
command("make").current_dir(&out_dir).arg(format!("-j{}", builder.jobs())).run(builder); | ||
command("make").current_dir(&out_dir).arg("install").run(builder); | ||
|
||
let lib_alias = install_dir.join("lib/libgccjit.so.0"); | ||
if !lib_alias.exists() { | ||
t!(builder.symlink_file(install_dir.join("lib/libgccjit.so"), lib_alias,)); | ||
} | ||
|
||
t!(stamp.write()); | ||
|
||
true | ||
} | ||
} |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.