Skip to content

Commit 5afb0fa

Browse files
Auto merge of #149921 - Kobzol:src-gpl, r=<try>
Add new source component that includes GPL-licensed source try-job: dist-x86_64-linux
2 parents 24139cf + 0d2a418 commit 5afb0fa

File tree

3 files changed

+133
-97
lines changed

3 files changed

+133
-97
lines changed

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 129 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,9 @@ impl Step for Src {
12111211
}
12121212
}
12131213

1214+
/// Tarball for people who want to build rustc and other components from the source.
1215+
/// Does not contain GPL code, which is separated into `PlainSourceTarballGpl`
1216+
/// for licensing reasons.
12141217
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
12151218
pub struct PlainSourceTarball;
12161219

@@ -1233,51 +1236,18 @@ impl Step for PlainSourceTarball {
12331236

12341237
/// Creates the plain source tarball
12351238
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
1236-
// NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which
1237-
// means neither rustup nor rustup-toolchain-install-master know how to download it.
1238-
// It also contains symbolic links, unlike other any other dist tarball.
1239-
// It's used for distros building rustc from source in a pre-vendored environment.
1240-
let mut tarball = Tarball::new(builder, "rustc", "src");
1241-
tarball.permit_symlinks(true);
1242-
let plain_dst_src = tarball.image_dir();
1243-
1244-
// This is the set of root paths which will become part of the source package
1245-
let src_files = [
1246-
// tidy-alphabetical-start
1247-
".gitmodules",
1248-
"CONTRIBUTING.md",
1249-
"COPYRIGHT",
1250-
"Cargo.lock",
1251-
"Cargo.toml",
1252-
"LICENSE-APACHE",
1253-
"LICENSE-MIT",
1254-
"README.md",
1255-
"RELEASES.md",
1256-
"REUSE.toml",
1257-
"bootstrap.example.toml",
1258-
"configure",
1259-
"license-metadata.json",
1260-
"package.json",
1261-
"x",
1262-
"x.ps1",
1263-
"x.py",
1264-
"yarn.lock",
1265-
// tidy-alphabetical-end
1266-
];
1267-
let src_dirs = ["src", "compiler", "library", "tests", "LICENSES"];
1268-
1269-
copy_src_dirs(
1239+
let tarball = prepare_source_tarball(
12701240
builder,
1271-
&builder.src,
1272-
&src_dirs,
1241+
"src",
12731242
&[
12741243
// We don't currently use the GCC source code for building any official components,
12751244
// it is very big, and has unclear licensing implications due to being GPL licensed.
12761245
// We thus exclude it from the source tarball from now.
12771246
"src/gcc",
12781247
],
1279-
plain_dst_src,
12801248
);
1249+
1250+
let plain_dst_src = tarball.image_dir();
12811251
// We keep something in src/gcc because it is a registered submodule,
12821252
// and if it misses completely it can cause issues elsewhere
12831253
// (see https://github.com/rust-lang/rust/issues/137332).
@@ -1289,76 +1259,138 @@ impl Step for PlainSourceTarball {
12891259
"The GCC source code is not included due to unclear licensing implications\n"
12901260
));
12911261
}
1262+
tarball.bare()
1263+
}
1264+
}
12921265

1293-
// Copy the files normally
1294-
for item in &src_files {
1295-
builder.copy_link(
1296-
&builder.src.join(item),
1297-
&plain_dst_src.join(item),
1298-
FileType::Regular,
1299-
);
1300-
}
1266+
/// Tarball with *all* source code for source builds, including GPL-licensed code.
1267+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1268+
pub struct PlainSourceTarballGpl;
13011269

1302-
// Create the version file
1303-
builder.create(&plain_dst_src.join("version"), &builder.rust_version());
1270+
impl Step for PlainSourceTarballGpl {
1271+
/// Produces the location of the tarball generated
1272+
type Output = GeneratedTarball;
1273+
const IS_HOST: bool = true;
13041274

1305-
// Create the files containing git info, to ensure --version outputs the same.
1306-
let write_git_info = |info: Option<&Info>, path: &Path| {
1307-
if let Some(info) = info {
1308-
t!(std::fs::create_dir_all(path));
1309-
channel::write_commit_hash_file(path, &info.sha);
1310-
channel::write_commit_info_file(path, info);
1311-
}
1312-
};
1313-
write_git_info(builder.rust_info().info(), plain_dst_src);
1314-
write_git_info(builder.cargo_info.info(), &plain_dst_src.join("./src/tools/cargo"));
1315-
1316-
if builder.config.dist_vendor {
1317-
builder.require_and_update_all_submodules();
1318-
1319-
// Vendor packages that are required by opt-dist to collect PGO profiles.
1320-
let pkgs_for_pgo_training = build_helper::LLVM_PGO_CRATES
1321-
.iter()
1322-
.chain(build_helper::RUSTC_PGO_CRATES)
1323-
.map(|pkg| {
1324-
let mut manifest_path =
1325-
builder.src.join("./src/tools/rustc-perf/collector/compile-benchmarks");
1326-
manifest_path.push(pkg);
1327-
manifest_path.push("Cargo.toml");
1328-
manifest_path
1329-
});
1330-
1331-
// Vendor all Cargo dependencies
1332-
let vendor = builder.ensure(Vendor {
1333-
sync_args: pkgs_for_pgo_training.collect(),
1334-
versioned_dirs: true,
1335-
root_dir: plain_dst_src.into(),
1336-
output_dir: VENDOR_DIR.into(),
1337-
});
1275+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1276+
run.alias("rustc-src-gpl")
1277+
}
13381278

1339-
let cargo_config_dir = plain_dst_src.join(".cargo");
1340-
builder.create_dir(&cargo_config_dir);
1341-
builder.create(&cargo_config_dir.join("config.toml"), &vendor.config);
1342-
}
1279+
fn is_default_step(builder: &Builder<'_>) -> bool {
1280+
builder.config.rust_dist_src
1281+
}
13431282

1344-
// Delete extraneous directories
1345-
// FIXME: if we're managed by git, we should probably instead ask git if the given path
1346-
// is managed by it?
1347-
for entry in walkdir::WalkDir::new(tarball.image_dir())
1348-
.follow_links(true)
1349-
.into_iter()
1350-
.filter_map(|e| e.ok())
1351-
{
1352-
if entry.path().is_dir() && entry.path().file_name() == Some(OsStr::new("__pycache__"))
1353-
{
1354-
t!(fs::remove_dir_all(entry.path()));
1355-
}
1356-
}
1283+
fn make_run(run: RunConfig<'_>) {
1284+
run.builder.ensure(PlainSourceTarballGpl);
1285+
}
13571286

1287+
/// Creates the plain source tarball
1288+
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
1289+
let tarball = prepare_source_tarball(builder, "src-gpl", &[]);
13581290
tarball.bare()
13591291
}
13601292
}
13611293

1294+
fn prepare_source_tarball<'a>(
1295+
builder: &'a Builder<'a>,
1296+
name: &str,
1297+
exclude_dirs: &[&str],
1298+
) -> Tarball<'a> {
1299+
// NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which
1300+
// means neither rustup nor rustup-toolchain-install-master know how to download it.
1301+
// It also contains symbolic links, unlike other any other dist tarball.
1302+
// It's used for distros building rustc from source in a pre-vendored environment.
1303+
let mut tarball = Tarball::new(builder, "rustc", name);
1304+
tarball.permit_symlinks(true);
1305+
let plain_dst_src = tarball.image_dir();
1306+
1307+
// This is the set of root paths which will become part of the source package
1308+
let src_files = [
1309+
// tidy-alphabetical-start
1310+
".gitmodules",
1311+
"CONTRIBUTING.md",
1312+
"COPYRIGHT",
1313+
"Cargo.lock",
1314+
"Cargo.toml",
1315+
"LICENSE-APACHE",
1316+
"LICENSE-MIT",
1317+
"README.md",
1318+
"RELEASES.md",
1319+
"REUSE.toml",
1320+
"bootstrap.example.toml",
1321+
"configure",
1322+
"license-metadata.json",
1323+
"package.json",
1324+
"x",
1325+
"x.ps1",
1326+
"x.py",
1327+
"yarn.lock",
1328+
// tidy-alphabetical-end
1329+
];
1330+
let src_dirs = ["src", "compiler", "library", "tests", "LICENSES"];
1331+
1332+
copy_src_dirs(builder, &builder.src, &src_dirs, exclude_dirs, plain_dst_src);
1333+
1334+
// Copy the files normally
1335+
for item in &src_files {
1336+
builder.copy_link(&builder.src.join(item), &plain_dst_src.join(item), FileType::Regular);
1337+
}
1338+
1339+
// Create the version file
1340+
builder.create(&plain_dst_src.join("version"), &builder.rust_version());
1341+
1342+
// Create the files containing git info, to ensure --version outputs the same.
1343+
let write_git_info = |info: Option<&Info>, path: &Path| {
1344+
if let Some(info) = info {
1345+
t!(std::fs::create_dir_all(path));
1346+
channel::write_commit_hash_file(path, &info.sha);
1347+
channel::write_commit_info_file(path, info);
1348+
}
1349+
};
1350+
write_git_info(builder.rust_info().info(), plain_dst_src);
1351+
write_git_info(builder.cargo_info.info(), &plain_dst_src.join("./src/tools/cargo"));
1352+
1353+
if builder.config.dist_vendor {
1354+
builder.require_and_update_all_submodules();
1355+
1356+
// Vendor packages that are required by opt-dist to collect PGO profiles.
1357+
let pkgs_for_pgo_training =
1358+
build_helper::LLVM_PGO_CRATES.iter().chain(build_helper::RUSTC_PGO_CRATES).map(|pkg| {
1359+
let mut manifest_path =
1360+
builder.src.join("./src/tools/rustc-perf/collector/compile-benchmarks");
1361+
manifest_path.push(pkg);
1362+
manifest_path.push("Cargo.toml");
1363+
manifest_path
1364+
});
1365+
1366+
// Vendor all Cargo dependencies
1367+
let vendor = builder.ensure(Vendor {
1368+
sync_args: pkgs_for_pgo_training.collect(),
1369+
versioned_dirs: true,
1370+
root_dir: plain_dst_src.into(),
1371+
output_dir: VENDOR_DIR.into(),
1372+
});
1373+
1374+
let cargo_config_dir = plain_dst_src.join(".cargo");
1375+
builder.create_dir(&cargo_config_dir);
1376+
builder.create(&cargo_config_dir.join("config.toml"), &vendor.config);
1377+
}
1378+
1379+
// Delete extraneous directories
1380+
// FIXME: if we're managed by git, we should probably instead ask git if the given path
1381+
// is managed by it?
1382+
for entry in walkdir::WalkDir::new(tarball.image_dir())
1383+
.follow_links(true)
1384+
.into_iter()
1385+
.filter_map(|e| e.ok())
1386+
{
1387+
if entry.path().is_dir() && entry.path().file_name() == Some(OsStr::new("__pycache__")) {
1388+
t!(fs::remove_dir_all(entry.path()));
1389+
}
1390+
}
1391+
tarball
1392+
}
1393+
13621394
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
13631395
pub struct Cargo {
13641396
pub build_compiler: Compiler,

src/bootstrap/src/core/builder/cli_paths/snapshots/x_dist.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ expression: dist
2929
[Dist] dist::PlainSourceTarball
3030
targets: [x86_64-unknown-linux-gnu]
3131
- Set({dist::rustc-src})
32+
[Dist] dist::PlainSourceTarballGpl
33+
targets: [x86_64-unknown-linux-gnu]
34+
- Set({dist::rustc-src-gpl})
3235
[Dist] dist::ReproducibleArtifacts
3336
targets: [x86_64-unknown-linux-gnu]
3437
- Set({dist::reproducible-artifacts})

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ impl<'a> Builder<'a> {
986986
// and force us to rebuild tools after vendoring dependencies.
987987
// To work around this, create the Tarball after building all the tools.
988988
dist::PlainSourceTarball,
989+
dist::PlainSourceTarballGpl,
989990
dist::BuildManifest,
990991
dist::ReproducibleArtifacts,
991992
dist::Gcc

0 commit comments

Comments
 (0)