[llvm] 998ad08 - Reland [gn build] Support linux/win compiler-rt cross compilation
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 09:59:09 PST 2023
Author: Arthur Eubanks
Date: 2023-02-17T09:58:28-08:00
New Revision: 998ad085e865f2e5acc589d6bee0e3379042da2e
URL: https://github.com/llvm/llvm-project/commit/998ad085e865f2e5acc589d6bee0e3379042da2e
DIFF: https://github.com/llvm/llvm-project/commit/998ad085e865f2e5acc589d6bee0e3379042da2e.diff
LOG: Reland [gn build] Support linux/win compiler-rt cross compilation
Differential Revision: https://reviews.llvm.org/D143545
Added:
Modified:
llvm/utils/gn/build/toolchain/BUILD.gn
llvm/utils/gn/build/toolchain/compiler.gni
llvm/utils/gn/secondary/compiler-rt/BUILD.gn
llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn
Removed:
################################################################################
diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index 80e5bd92a1ad8..02a741dafe4af 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -9,6 +9,8 @@ declare_args() {
assert(!use_goma || goma_dir != "",
"set `goma_dir` to the output of `goma_ctl goma_dir` in your args.gn")
+unix_copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
+
template("unix_toolchain") {
toolchain(target_name) {
# https://groups.google.com/a/chromium.org/g/gn-dev/c/F_lv5T-tNDM
@@ -144,9 +146,8 @@ template("unix_toolchain") {
default_output_dir = "{{root_out_dir}}/bin"
}
- copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
tool("copy") {
- command = copy_command
+ command = unix_copy_command
description = "COPY {{source}} {{output}}"
}
@@ -156,7 +157,7 @@ template("unix_toolchain") {
_copydir = "cd {{source}} && " +
"find . | cpio -pdl \"\$OLDPWD\"/{{output}} 2>/dev/null"
command = "rm -rf {{output}} && if [[ -d {{source}} ]]; then " +
- _copydir + "; else " + copy_command + "; fi"
+ _copydir + "; else " + unix_copy_command + "; fi"
description = "COPY_BUNDLE_DATA {{source}} {{output}}"
}
tool("compile_xcassets") {
@@ -378,14 +379,23 @@ template("win_toolchain") {
}
tool("copy") {
- # GN hands out slash-using paths, but cmd's copy needs backslashes.
- # Use cmd's %foo:a=b% substitution feature to convert.
- command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul"
+ if (host_os == "win") {
+ # GN hands out slash-using paths, but cmd's copy needs backslashes.
+ # Use cmd's %foo:a=b% substitution feature to convert.
+ command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul"
+ } else {
+ command = unix_copy_command
+ }
+
description = "COPY {{source}} {{output}}"
}
tool("stamp") {
- command = "cmd /c type nul > {{output}}"
+ if (host_os == "win") {
+ command = "cmd /c type nul > {{output}}"
+ } else {
+ command = "touch {{output}}"
+ }
description = "STAMP {{output}}"
}
}
@@ -398,11 +408,14 @@ win_toolchain("win") {
}
}
-win_toolchain("stage2_win") {
+win_toolchain("stage2_win_x64") {
toolchain_args = {
- current_os = host_os
- current_cpu = host_cpu
+ current_os = "win"
+ current_cpu = "x64"
+ if (host_os != "win") {
+ sysroot = win_sysroot
+ }
clang_base_path = root_build_dir
use_goma = false
}
@@ -414,9 +427,12 @@ win_toolchain("stage2_win") {
win_toolchain("stage2_win_x86") {
toolchain_args = {
- current_os = host_os
+ current_os = "win"
current_cpu = "x86"
+ if (host_os != "win") {
+ sysroot = win_sysroot
+ }
clang_base_path = root_build_dir
use_goma = false
}
diff --git a/llvm/utils/gn/build/toolchain/compiler.gni b/llvm/utils/gn/build/toolchain/compiler.gni
index 28efe991bee86..7cd15e658a087 100644
--- a/llvm/utils/gn/build/toolchain/compiler.gni
+++ b/llvm/utils/gn/build/toolchain/compiler.gni
@@ -13,6 +13,9 @@ declare_args() {
# Set this to the path to Android NDK r21. If set, cross compilation targeting
# Android will be enabled.
android_ndk_path = ""
+
+ # Set this to the path of the Win SDK. Only used for cross compilation. If set, cross compilation targeting Windows will be enabled.
+ win_sysroot = ""
}
declare_args() {
@@ -23,3 +26,7 @@ declare_args() {
# Set this to true to link with LLD instead of the default linker.
use_lld = clang_base_path != ""
}
+
+assert(
+ !(host_os == "win" && win_sysroot != ""),
+ "win_sysroot should only be used for cross compilation, use sysroot on Windows")
diff --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
index edadd265833b9..b31016108419e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
@@ -5,11 +5,13 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
# In the GN build, compiler-rt is always built by just-built clang and lld.
# FIXME: For macOS and iOS builds, depend on lib in all needed target arch
# toolchains and then lipo them together for the final output.
-if (current_os == "win") {
- supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_win" ]
+supported_toolchains = []
+if (current_os == "win" || win_sysroot != "") {
+ supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win_x64" ]
supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win_x86" ]
-} else {
- supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
+}
+if (current_os != "win") {
+ supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
}
supported_toolchains += supported_android_toolchains
if (llvm_build_AArch64) {
diff --git a/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn
index 27ab789ae7b74..453ee8d5e05e9 100644
--- a/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn
@@ -48,8 +48,9 @@ supported_toolchains = []
if (host_os == "linux") {
supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
} else if (host_os == "win") {
- supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win" ]
+ supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win_x64" ]
}
+
group("asan") {
deps = []
foreach(toolchain, supported_toolchains) {
More information about the llvm-commits
mailing list