Modify build_system's prepare stage to allow for custom sysroot source path
This commit is contained in:
parent
41839175b0
commit
04932ea22f
@ -5,13 +5,24 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
fn prepare_libcore(
|
fn prepare_libcore(
|
||||||
sysroot_path: &Path,
|
sysroot_path: &Path,
|
||||||
libgccjit12_patches: bool,
|
libgccjit12_patches: bool,
|
||||||
cross_compile: bool,
|
cross_compile: bool,
|
||||||
|
sysroot_source: Option<String>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
let rustlib_dir: PathBuf;
|
||||||
|
|
||||||
|
if let Some(path) = sysroot_source {
|
||||||
|
rustlib_dir = Path::new(&path)
|
||||||
|
.canonicalize()
|
||||||
|
.map_err(|error| format!("Failed to canonicalize path: {:?}", error))?;
|
||||||
|
if !rustlib_dir.is_dir() {
|
||||||
|
return Err(format!("Custom sysroot path {:?} not found", rustlib_dir));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
let rustc_path = match get_rustc_path() {
|
let rustc_path = match get_rustc_path() {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => return Err("`rustc` path not found".to_string()),
|
None => return Err("`rustc` path not found".to_string()),
|
||||||
@ -22,13 +33,14 @@ fn prepare_libcore(
|
|||||||
None => return Err(format!("No parent for `{}`", rustc_path.display())),
|
None => return Err(format!("No parent for `{}`", rustc_path.display())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let rustlib_dir = parent
|
rustlib_dir = parent
|
||||||
.join("../lib/rustlib/src/rust")
|
.join("../lib/rustlib/src/rust")
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.map_err(|error| format!("Failed to canonicalize path: {:?}", error))?;
|
.map_err(|error| format!("Failed to canonicalize path: {:?}", error))?;
|
||||||
if !rustlib_dir.is_dir() {
|
if !rustlib_dir.is_dir() {
|
||||||
return Err("Please install `rust-src` component".to_string());
|
return Err("Please install `rust-src` component".to_string());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sysroot_dir = sysroot_path.join("sysroot_src");
|
let sysroot_dir = sysroot_path.join("sysroot_src");
|
||||||
if sysroot_dir.is_dir() {
|
if sysroot_dir.is_dir() {
|
||||||
@ -151,6 +163,7 @@ struct PrepareArg {
|
|||||||
cross_compile: bool,
|
cross_compile: bool,
|
||||||
only_libcore: bool,
|
only_libcore: bool,
|
||||||
libgccjit12_patches: bool,
|
libgccjit12_patches: bool,
|
||||||
|
sysroot_source: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrepareArg {
|
impl PrepareArg {
|
||||||
@ -158,12 +171,23 @@ fn new() -> Result<Option<Self>, String> {
|
|||||||
let mut only_libcore = false;
|
let mut only_libcore = false;
|
||||||
let mut cross_compile = false;
|
let mut cross_compile = false;
|
||||||
let mut libgccjit12_patches = false;
|
let mut libgccjit12_patches = false;
|
||||||
|
let mut sysroot_source = None;
|
||||||
|
|
||||||
for arg in std::env::args().skip(2) {
|
let mut args = std::env::args().skip(2);
|
||||||
|
while let Some(arg) = args.next() {
|
||||||
match arg.as_str() {
|
match arg.as_str() {
|
||||||
"--only-libcore" => only_libcore = true,
|
"--only-libcore" => only_libcore = true,
|
||||||
"--cross" => cross_compile = true,
|
"--cross" => cross_compile = true,
|
||||||
"--libgccjit12-patches" => libgccjit12_patches = true,
|
"--libgccjit12-patches" => libgccjit12_patches = true,
|
||||||
|
"--sysroot-source" => {
|
||||||
|
if let Some(path) = args.next() {
|
||||||
|
sysroot_source = Some(path);
|
||||||
|
} else {
|
||||||
|
return Err(
|
||||||
|
"Expected a value after `--sysroot-source`, found nothing".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
"--help" => {
|
"--help" => {
|
||||||
Self::usage();
|
Self::usage();
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
@ -171,7 +195,7 @@ fn new() -> Result<Option<Self>, String> {
|
|||||||
a => return Err(format!("Unknown argument `{a}`")),
|
a => return Err(format!("Unknown argument `{a}`")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Some(Self { cross_compile, only_libcore, libgccjit12_patches }))
|
Ok(Some(Self { cross_compile, only_libcore, libgccjit12_patches, sysroot_source }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage() {
|
fn usage() {
|
||||||
@ -182,6 +206,7 @@ fn usage() {
|
|||||||
--only-libcore : Only setup libcore and don't clone other repositories
|
--only-libcore : Only setup libcore and don't clone other repositories
|
||||||
--cross : Apply the patches needed to do cross-compilation
|
--cross : Apply the patches needed to do cross-compilation
|
||||||
--libgccjit12-patches : Apply patches needed for libgccjit12
|
--libgccjit12-patches : Apply patches needed for libgccjit12
|
||||||
|
--sysroot-source : Specify custom path for sysroot source
|
||||||
--help : Show this help"#
|
--help : Show this help"#
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -193,7 +218,12 @@ pub fn run() -> Result<(), String> {
|
|||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
let sysroot_path = get_sysroot_dir();
|
let sysroot_path = get_sysroot_dir();
|
||||||
prepare_libcore(&sysroot_path, args.libgccjit12_patches, args.cross_compile)?;
|
prepare_libcore(
|
||||||
|
&sysroot_path,
|
||||||
|
args.libgccjit12_patches,
|
||||||
|
args.cross_compile,
|
||||||
|
args.sysroot_source,
|
||||||
|
)?;
|
||||||
|
|
||||||
if !args.only_libcore {
|
if !args.only_libcore {
|
||||||
cargo_install("hyperfine")?;
|
cargo_install("hyperfine")?;
|
||||||
|
@ -35,6 +35,14 @@ COLLECT_NO_DEMANGLE=1
|
|||||||
* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).
|
* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).
|
||||||
* Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.
|
* Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.
|
||||||
|
|
||||||
|
### How to use a custom sysroot source path
|
||||||
|
|
||||||
|
If you wish to build a custom sysroot, pass the path of your sysroot source to `--sysroot-source` during the `prepare` step, like so:
|
||||||
|
|
||||||
|
```
|
||||||
|
./y.sh prepare --sysroot-source /path/to/custom/source
|
||||||
|
```
|
||||||
|
|
||||||
### How to use [mem-trace](https://github.com/antoyo/mem-trace)
|
### How to use [mem-trace](https://github.com/antoyo/mem-trace)
|
||||||
|
|
||||||
`rustc` needs to be built without `jemalloc` so that `mem-trace` can overload `malloc` since `jemalloc` is linked statically, so a `LD_PRELOAD`-ed library won't a chance to intercept the calls to `malloc`.
|
`rustc` needs to be built without `jemalloc` so that `mem-trace` can overload `malloc` since `jemalloc` is linked statically, so a `LD_PRELOAD`-ed library won't a chance to intercept the calls to `malloc`.
|
||||||
|
Loading…
Reference in New Issue
Block a user