Support my laptop
This commit is contained in:
parent
60ab50e89e
commit
751088d7e0
|
|
@ -1,5 +1,6 @@
|
||||||
use fslock::LockFile;
|
use fslock::LockFile;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
@ -129,11 +130,10 @@ fn get_boringssl_source_path(config: &Config) -> &PathBuf {
|
||||||
if !submodule_path.join("CMakeLists.txt").exists() {
|
if !submodule_path.join("CMakeLists.txt").exists() {
|
||||||
println!("cargo:warning=fetching boringssl git submodule");
|
println!("cargo:warning=fetching boringssl git submodule");
|
||||||
|
|
||||||
run_command(
|
run_command(&["git"], |c| {
|
||||||
Command::new("git")
|
c.args(["submodule", "update", "--init", "--recursive"])
|
||||||
.args(["submodule", "update", "--init", "--recursive"])
|
.arg(&submodule_path)
|
||||||
.arg(&submodule_path),
|
})
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -496,7 +496,7 @@ fn ensure_patches_applied(config: &Config) -> io::Result<()> {
|
||||||
|
|
||||||
// NOTE: init git in the copied files, so we can apply patches
|
// NOTE: init git in the copied files, so we can apply patches
|
||||||
if !has_git {
|
if !has_git {
|
||||||
run_command(Command::new("git").arg("init").current_dir(src_path))?;
|
run_command(&["git"], |c| c.arg("init").current_dir(src_path))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("cargo:warning=applying 44b3df6f03d85c901767250329c571db405122d5 patch to boringssl");
|
println!("cargo:warning=applying 44b3df6f03d85c901767250329c571db405122d5 patch to boringssl");
|
||||||
|
|
@ -535,32 +535,46 @@ fn apply_patch(config: &Config, patch_name: &str) -> io::Result<()> {
|
||||||
args.push("-p2");
|
args.push("-p2");
|
||||||
}
|
}
|
||||||
|
|
||||||
run_command(
|
run_command(&["git"], |c| {
|
||||||
Command::new("git")
|
c.args(&args).arg(&cmd_path).current_dir(src_path)
|
||||||
.args(&args)
|
})?;
|
||||||
.arg(cmd_path)
|
|
||||||
.current_dir(src_path),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_command(command: &mut Command) -> io::Result<Output> {
|
fn run_command(
|
||||||
let out = command.output()?;
|
names: &[impl AsRef<OsStr>],
|
||||||
|
f: impl Fn(&mut Command) -> &mut Command,
|
||||||
|
) -> io::Result<Output> {
|
||||||
|
for name in names {
|
||||||
|
let mut command = Command::new(name);
|
||||||
|
f(&mut command);
|
||||||
|
|
||||||
println!("{}", std::str::from_utf8(&out.stdout).unwrap());
|
let out = match command.output() {
|
||||||
eprintln!("{}", std::str::from_utf8(&out.stderr).unwrap());
|
Ok(out) => out,
|
||||||
|
Err(e) if e.kind() == io::ErrorKind::NotFound => continue,
|
||||||
if !out.status.success() {
|
Err(e) => {
|
||||||
let err = match out.status.code() {
|
eprintln!("{command:?} failed to execute: {e}");
|
||||||
Some(code) => format!("{command:?} exited with status: {code}"),
|
continue;
|
||||||
None => format!("{command:?} was terminated by signal"),
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Err(io::Error::other(err));
|
println!("{}", std::str::from_utf8(&out.stdout).unwrap());
|
||||||
|
eprintln!("{}", std::str::from_utf8(&out.stderr).unwrap());
|
||||||
|
|
||||||
|
if !out.status.success() {
|
||||||
|
let err = match out.status.code() {
|
||||||
|
Some(code) => format!("{command:?} exited with status: {code}"),
|
||||||
|
None => format!("{command:?} was terminated by signal"),
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(io::Error::other(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(out)
|
Err(io::ErrorKind::NotFound.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn built_boring_source_path(config: &Config) -> &PathBuf {
|
fn built_boring_source_path(config: &Config) -> &PathBuf {
|
||||||
|
|
@ -620,13 +634,8 @@ fn link_in_precompiled_bcm_o(config: &Config) {
|
||||||
fs::copy(bcm_o_src_path, &bcm_o_dst_path).unwrap();
|
fs::copy(bcm_o_src_path, &bcm_o_dst_path).unwrap();
|
||||||
|
|
||||||
// check that fips module is named as expected
|
// check that fips module is named as expected
|
||||||
let out = run_command(
|
let ar = &["ar", "llvm-ar"];
|
||||||
Command::new("ar")
|
let out = run_command(ar, |c| c.arg("t").arg(&libcrypto_path).arg("bcm.o")).unwrap();
|
||||||
.arg("t")
|
|
||||||
.arg(&libcrypto_path)
|
|
||||||
.arg("bcm.o"),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8(out.stdout).unwrap().trim(),
|
String::from_utf8(out.stdout).unwrap().trim(),
|
||||||
|
|
@ -639,11 +648,10 @@ fn link_in_precompiled_bcm_o(config: &Config) {
|
||||||
// (this causes the need for extra linker flags to deal with duplicate symbols)
|
// (this causes the need for extra linker flags to deal with duplicate symbols)
|
||||||
// (as long as the newer module does not define new symbols, one may also remove it,
|
// (as long as the newer module does not define new symbols, one may also remove it,
|
||||||
// but once there are new symbols it would cause missing symbols at linking stage)
|
// but once there are new symbols it would cause missing symbols at linking stage)
|
||||||
run_command(
|
run_command(ar, |c| {
|
||||||
Command::new("ar")
|
c.args(["rb", "bcm.o"])
|
||||||
.args(["rb", "bcm.o"])
|
.args([&libcrypto_path, &bcm_o_dst_path])
|
||||||
.args([&libcrypto_path, &bcm_o_dst_path]),
|
})
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{config::Config, pick_best_android_ndk_toolchain, run_command};
|
use crate::{config::Config, pick_best_android_ndk_toolchain, run_command};
|
||||||
use std::{fs, io::Write, path::PathBuf, process::Command};
|
use std::{fs, io::Write, path::PathBuf};
|
||||||
|
|
||||||
// The prefix to add to all symbols
|
// The prefix to add to all symbols
|
||||||
// RBSSL = Rust BoringSSL, chosen arbitrarily to avoid collisions with other projects
|
// RBSSL = Rust BoringSSL, chosen arbitrarily to avoid collisions with other projects
|
||||||
|
|
@ -32,14 +32,20 @@ fn android_toolchain(config: &Config) -> PathBuf {
|
||||||
|
|
||||||
pub fn prefix_symbols(config: &Config) {
|
pub fn prefix_symbols(config: &Config) {
|
||||||
// List static libraries to prefix symbols in
|
// List static libraries to prefix symbols in
|
||||||
|
eprintln!("{:?}", config.out_dir);
|
||||||
|
eprintln!("{:?}", config.out_dir);
|
||||||
|
eprintln!("{:?}", config.out_dir);
|
||||||
|
eprintln!("{:?}", config.out_dir);
|
||||||
let static_libs: Vec<PathBuf> = [
|
let static_libs: Vec<PathBuf> = [
|
||||||
config.out_dir.join("build"),
|
config.out_dir.join("build"),
|
||||||
config.out_dir.join("build").join("ssl"),
|
config.out_dir.join("build").join("ssl"),
|
||||||
config.out_dir.join("build").join("crypto"),
|
config.out_dir.join("build").join("crypto"),
|
||||||
|
config.out_dir.join("build").join("Debug"),
|
||||||
|
config.out_dir.join("build").join("Release"),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|dir| {
|
.flat_map(|dir| {
|
||||||
["libssl.a", "libcrypto.a"]
|
["libssl.a", "libcrypto.a", "ssl.lib", "crypto.lib"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |file| PathBuf::from(dir).join(file))
|
.map(move |file| PathBuf::from(dir).join(file))
|
||||||
})
|
})
|
||||||
|
|
@ -47,11 +53,11 @@ pub fn prefix_symbols(config: &Config) {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Use `nm` to list symbols in these static libraries
|
// Use `nm` to list symbols in these static libraries
|
||||||
let nm = match &*config.target_os {
|
let nm: &[PathBuf] = match &*config.target_os {
|
||||||
"android" => android_toolchain(config).join("llvm-nm"),
|
"android" => &[android_toolchain(config).join("llvm-nm")],
|
||||||
_ => PathBuf::from("nm"),
|
_ => &[PathBuf::from("nm"), PathBuf::from("llvm-nm")],
|
||||||
};
|
};
|
||||||
let out = run_command(Command::new(nm).args(&static_libs)).unwrap();
|
let out = run_command(nm, |c| c.args(&static_libs)).unwrap();
|
||||||
let mut redefine_syms: Vec<String> = String::from_utf8_lossy(&out.stdout)
|
let mut redefine_syms: Vec<String> = String::from_utf8_lossy(&out.stdout)
|
||||||
.lines()
|
.lines()
|
||||||
.filter(|l| {
|
.filter(|l| {
|
||||||
|
|
@ -74,16 +80,15 @@ pub fn prefix_symbols(config: &Config) {
|
||||||
f.flush().unwrap();
|
f.flush().unwrap();
|
||||||
|
|
||||||
// Use `objcopy` to prefix symbols in these static libraries
|
// Use `objcopy` to prefix symbols in these static libraries
|
||||||
let objcopy = match &*config.target_os {
|
let objcopy: &[PathBuf] = match &*config.target_os {
|
||||||
"android" => android_toolchain(config).join("llvm-objcopy"),
|
"android" => &[android_toolchain(config).join("llvm-objcopy")],
|
||||||
_ => PathBuf::from("objcopy"),
|
_ => &[PathBuf::from("objcopy"), PathBuf::from("llvm-objcopy")],
|
||||||
};
|
};
|
||||||
for static_lib in &static_libs {
|
for static_lib in &static_libs {
|
||||||
run_command(
|
run_command(objcopy, |c| {
|
||||||
Command::new(&objcopy)
|
c.arg(format!("--redefine-syms={}", redefine_syms_path.display()))
|
||||||
.arg(format!("--redefine-syms={}", redefine_syms_path.display()))
|
.arg(static_lib)
|
||||||
.arg(static_lib),
|
})
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ features = ["pq-experimental", "underscore-wildcards"]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["prefix-symbols"]
|
||||||
|
|
||||||
# Controlling the build
|
# Controlling the build
|
||||||
|
|
||||||
# NOTE: This feature is deprecated. It is needed for the submoduled
|
# NOTE: This feature is deprecated. It is needed for the submoduled
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue