Update to latest Rust upstream

This commit is contained in:
topjohnwu 2022-06-23 01:01:51 -07:00
parent 2425c369bc
commit 9a5879ece0
10 changed files with 218 additions and 119 deletions

View File

@ -53,6 +53,8 @@ build() {
--build $TRIPLE install
cd ../
RUST_CLANG=$(rust/build/$TRIPLE/llvm/bin/llvm-config --version)
cd out
cp -af ../rust/build/$TRIPLE/llvm/bin llvm-bin
cp -af ../rust/build/$TRIPLE/lld/bin/. llvm-bin/.

View File

@ -41,6 +41,8 @@ build() {
python3 ./x.py --config "../config-${OS}.toml" --host $TRIPLE install
cd ../
RUST_CLANG=$(rust/build/$TRIPLE/llvm/bin/llvm-config --version)
cd out
cp -af ../rust/build/$TRIPLE/llvm/bin llvm-bin
cp -af ../rust/build/$TRIPLE/llvm/lib/clang/$RUST_CLANG/include clang-include

View File

@ -1,28 +1,19 @@
# Copyright 2022 Google LLC.
# SPDX-License-Identifier: Apache-2.0
RUST_VERSION='beta'
RUST_VERSION='master'
NDK_VERSION='r24'
OUTPUT_VERSION='r24.1'
OUTPUT_VERSION='r24.2'
RUST_CLANG='14.0.0'
NDK_CLANG='14.0.1'
clone() {
git clone --depth 1 --branch $RUST_VERSION https://github.com/rust-lang/rust.git
cd rust
git submodule update --init --depth=1
patch -p1 < ../patches/patch-bootstrap-native.patch
patch -p1 < ../patches/forced-vendored-openssl.patch
if [ $OS = 'darwin' ]; then
# Dirty fix of llvm-config for macOS
cd src/llvm-project
patch -p1 < ../../../patches/fix-llvm-config.patch
cd ../../
fi
for p in ../patches/*.patch; do
patch -p1 < $p
done
cd ../
}

View File

@ -0,0 +1,54 @@
From ddb4041c3ae54d41eb4dff45e42bdb25a8b738d5 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@google.com>
Date: Tue, 21 Jun 2022 01:31:16 -0700
Subject: [PATCH 1/4] Fix cross compiling on macOS
When cross compiling LLVM on an arm64 machine to x86_64, CMake will
produce universal binaries by default, causing link errors. Explicitly
set CMAKE_OSX_ARCHITECTURES to the one single target architecture.
---
src/bootstrap/native.rs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 329bb68672e..ece02499d24 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -416,7 +416,6 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
// should use llvm-tblgen from there, also should verify that it
// actually exists most of the time in normal installs of LLVM.
let host_bin = builder.llvm_out(builder.config.build).join("bin");
- cfg.define("CMAKE_CROSSCOMPILING", "True");
cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
cfg.define(
@@ -513,6 +512,8 @@ fn configure_cmake(
cfg.target(&target.triple).host(&builder.config.build.triple);
if target != builder.config.build {
+ cfg.define("CMAKE_CROSSCOMPILING", "True");
+
if target.contains("netbsd") {
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
} else if target.contains("freebsd") {
@@ -530,6 +531,17 @@ fn configure_cmake(
// Since, the LLVM itself makes rather limited use of version checks in
// CMakeFiles (and then only in tests), and so far no issues have been
// reported, the system version is currently left unset.
+
+ if target.contains("darwin") {
+ // Make sure that CMake does not build universal binaries on macOS.
+ // Explicitly specifiy the one single target architecture.
+ if target.starts_with("aarch64") {
+ // macOS uses a different name for building arm64
+ cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
+ } else {
+ cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
+ }
+ }
}
let sanitize_cc = |cc: &Path| {
--
2.36.1

View File

@ -0,0 +1,37 @@
From b5a02a88ad628b1cfa019cc8efc1ce98d7ad5b49 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@google.com>
Date: Tue, 21 Jun 2022 01:58:37 -0700
Subject: [PATCH 2/4] Set CLANG_TABLEGEN when cross compiling clang
When cross compiling rustc with `llvm.clang = true`, CLANG_TABLEGEN
has to be set to the host clang-tblgen executable to build clang.
---
src/bootstrap/native.rs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index ece02499d24..dfbf16ef4b2 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -417,11 +417,17 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
// actually exists most of the time in normal installs of LLVM.
let host_bin = builder.llvm_out(builder.config.build).join("bin");
cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
- cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
cfg.define(
"LLVM_CONFIG_PATH",
host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
);
+ if builder.config.llvm_clang {
+ let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin");
+ cfg.define(
+ "CLANG_TABLEGEN",
+ build_bin.join("clang-tblgen").with_extension(EXE_EXTENSION),
+ );
+ }
}
if let Some(ref suffix) = builder.config.llvm_version_suffix {
--
2.36.1

View File

@ -0,0 +1,93 @@
From 06176cd81a3d2974c7ed564f039ba74759be9c7d Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@google.com>
Date: Wed, 22 Jun 2022 23:05:20 -0700
Subject: [PATCH 3/4] Allow dynamically linking against libLLVM on macOS
Create symlinks to workaround file missing error in llvm-config
---
src/bootstrap/native.rs | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index dfbf16ef4b2..04d8c8c07bd 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -239,7 +239,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
builder.update_submodule(&Path::new("src").join("llvm-project"));
if builder.llvm_link_shared()
- && (target.contains("windows") || target.contains("apple-darwin"))
+ && (target.contains("windows") || (target.contains("apple-darwin") && !cfg!(unix)))
{
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
}
@@ -346,7 +346,9 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
//
// If we're not linking rustc to a dynamic LLVM, though, then don't link
// tools to it.
- if builder.llvm_link_tools_dynamically(target) && builder.llvm_link_shared() {
+ let llvm_link_shared =
+ builder.llvm_link_tools_dynamically(target) && builder.llvm_link_shared();
+ if llvm_link_shared {
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
}
@@ -430,18 +432,21 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
}
}
+ let mut llvm_suffix: Option<String> = None;
if let Some(ref suffix) = builder.config.llvm_version_suffix {
// Allow version-suffix="" to not define a version suffix at all.
if !suffix.is_empty() {
- cfg.define("LLVM_VERSION_SUFFIX", suffix);
+ llvm_suffix = Some(suffix.to_string());
}
} else if builder.config.channel == "dev" {
// Changes to a version suffix require a complete rebuild of the LLVM.
// To avoid rebuilds during a time of version bump, don't include rustc
// release number on the dev channel.
- cfg.define("LLVM_VERSION_SUFFIX", "-rust-dev");
+ llvm_suffix = Some("-rust-dev".to_string())
} else {
- let suffix = format!("-rust-{}-{}", builder.version, builder.config.channel);
+ llvm_suffix = Some(format!("-rust-{}-{}", builder.version, builder.config.channel))
+ }
+ if let Some(ref suffix) = llvm_suffix {
cfg.define("LLVM_VERSION_SUFFIX", suffix);
}
@@ -470,6 +475,30 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
cfg.build();
+ // When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
+ // libLLVM.dylib will be built. However, llvm-config will still look
+ // for a versioned path like libLLVM-14.dylib. Manually create a symbolic
+ // link to make llvm-config happy.
+ #[cfg(unix)]
+ if llvm_link_shared && target.contains("apple-darwin") {
+ let mut cmd = Command::new(&build_llvm_config);
+ let version = output(cmd.arg("--version"));
+ let major = version.split('.').next().unwrap();
+ let lib_name = match llvm_suffix {
+ Some(s) => format!("lib/libLLVM-{}{}.dylib", major, s),
+ None => format!("lib/libLLVM-{}.dylib", major),
+ };
+
+ // The reason why we build the library path from llvm-config is because
+ // the output of llvm-config depends on its location in the file system.
+ // Make sure we create the symlink exactly where it's needed.
+ let llvm_base = build_llvm_config.parent().unwrap().parent().unwrap();
+ let lib_llvm = llvm_base.join(lib_name);
+ if std::os::unix::fs::symlink("libLLVM.dylib", &lib_llvm).is_err() {
+ panic!("unable to create symbolic link {:?}", lib_llvm.file_name());
+ }
+ }
+
t!(stamp.write());
build_llvm_config
--
2.36.1

View File

@ -0,0 +1,25 @@
From cd042bfd802ca7fa33e4ac378db57c3e0712443b Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@google.com>
Date: Wed, 22 Jun 2022 23:32:05 -0700
Subject: [PATCH 4/4] Force cargo to use vendored openssl
---
src/bootstrap/tool.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index 905fa431d29..9f422c1df59 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -613,7 +613,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
path: "src/tools/cargo",
is_optional_tool: false,
source_type: SourceType::Submodule,
- extra_features: Vec::new(),
+ extra_features: vec!["vendored-openssl".to_string()],
})
.expect("expected to build -- essential tool");
--
2.36.1

View File

@ -1,12 +0,0 @@
--- a/llvm/tools/llvm-config/llvm-config.cpp
+++ b/llvm/tools/llvm-config/llvm-config.cpp
@@ -424,8 +424,7 @@ int main(int argc, char **argv) {
const bool BuiltSharedLibs = !!LLVM_ENABLE_SHARED;
bool DyLibExists = false;
- const std::string DyLibName =
- (SharedPrefix + "LLVM-" + SharedVersionedExt).str();
+ const std::string DyLibName = (SharedPrefix + "LLVM." + SharedExt).str();
// If LLVM_LINK_DYLIB is ON, the single shared library will be returned
// for "--libs", etc, if they exist. This behaviour can be overridden with

View File

@ -1,10 +0,0 @@
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -617,7 +617,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
path: "src/tools/cargo",
is_optional_tool: false,
source_type: SourceType::Submodule,
- extra_features: Vec::new(),
+ extra_features: vec!["vendored-openssl".to_string()],
})
.expect("expected to build -- essential tool");

View File

@ -1,83 +0,0 @@
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -75,9 +75,6 @@ pub fn prebuilt_llvm_config(
let out_dir = builder.llvm_out(target);
let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
- if !builder.config.build.contains("msvc") || builder.ninja() {
- llvm_config_ret_dir.push("build");
- }
llvm_config_ret_dir.push("bin");
let build_llvm_config = llvm_config_ret_dir.join(exe("llvm-config", builder.config.build));
@@ -154,7 +151,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
builder.update_submodule(&Path::new("src").join("llvm-project"));
if builder.config.llvm_link_shared
- && (target.contains("windows") || target.contains("apple-darwin"))
+ && (target.contains("windows"))
{
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
}
@@ -241,13 +238,6 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
}
- if builder.config.llvm_thin_lto {
- cfg.define("LLVM_ENABLE_LTO", "Thin");
- if !target.contains("apple") {
- cfg.define("LLVM_ENABLE_LLD", "ON");
- }
- }
-
// This setting makes the LLVM tools link to the dynamic LLVM library,
// which saves both memory during parallel links and overall disk space
// for the tools. We don't do this on every platform as it doesn't work
@@ -325,8 +315,10 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
// should use llvm-tblgen from there, also should verify that it
// actually exists most of the time in normal installs of LLVM.
let host_bin = builder.llvm_out(builder.config.build).join("bin");
+ let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin");
cfg.define("CMAKE_CROSSCOMPILING", "True");
cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
+ cfg.define("CLANG_TABLEGEN", build_bin.join("clang-tblgen").with_extension(EXE_EXTENSION));
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
cfg.define(
"LLVM_CONFIG_PATH",
@@ -349,14 +341,6 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
cfg.define("LLVM_VERSION_SUFFIX", suffix);
}
- if let Some(ref linker) = builder.config.llvm_use_linker {
- cfg.define("LLVM_USE_LINKER", linker);
- }
-
- if builder.config.llvm_allow_old_toolchain {
- cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES");
- }
-
configure_cmake(builder, target, &mut cfg, true, ldflags);
for (key, val) in &builder.config.llvm_build_config {
@@ -513,6 +497,21 @@ fn configure_cmake(
.define("CMAKE_ASM_COMPILER", sanitize_cc(cc));
}
+ if builder.config.llvm_thin_lto {
+ cfg.define("LLVM_ENABLE_LTO", "Thin");
+ if !target.contains("apple") {
+ cfg.define("LLVM_ENABLE_LLD", "ON");
+ }
+ }
+
+ if let Some(ref linker) = builder.config.llvm_use_linker {
+ cfg.define("LLVM_USE_LINKER", linker);
+ }
+
+ if builder.config.llvm_allow_old_toolchain {
+ cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES");
+ }
+
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
let mut cflags: OsString = builder.cflags(target, GitRepo::Llvm, CLang::C).join(" ").into();
if let Some(ref s) = builder.config.llvm_cflags {