Skip to content

Commit a739f4d

Browse files
committed
gn build: Fix build when not building the native target.
Differential Revision: https://reviews.llvm.org/D127068
1 parent b92436e commit a739f4d

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,6 @@ write_cmake_config("llvm-config") {
329329
"LLVM_HAVE_TF_API=",
330330
"LLVM_HOST_TRIPLE=$llvm_current_triple",
331331
"LLVM_NATIVE_ARCH=$native_target",
332-
"LLVM_NATIVE_ASMPARSER=1",
333-
"LLVM_NATIVE_ASMPRINTER=1",
334-
"LLVM_NATIVE_DISASSEMBLER=1",
335-
"LLVM_NATIVE_TARGET=1",
336-
"LLVM_NATIVE_TARGETINFO=1",
337-
"LLVM_NATIVE_TARGETMC=1",
338-
"LLVM_NATIVE_TARGETMCA=1",
339332
"LLVM_UNREACHABLE_OPTIMIZE=1",
340333
"LLVM_USE_INTEL_JITEVENTS=",
341334
"LLVM_USE_OPROFILE=",
@@ -347,6 +340,28 @@ write_cmake_config("llvm-config") {
347340
"PACKAGE_VERSION=${llvm_version}git",
348341
]
349342

343+
if (llvm_build_native) {
344+
values += [
345+
"LLVM_NATIVE_ASMPARSER=1",
346+
"LLVM_NATIVE_ASMPRINTER=1",
347+
"LLVM_NATIVE_DISASSEMBLER=1",
348+
"LLVM_NATIVE_TARGET=1",
349+
"LLVM_NATIVE_TARGETINFO=1",
350+
"LLVM_NATIVE_TARGETMC=1",
351+
"LLVM_NATIVE_TARGETMCA=1",
352+
]
353+
} else {
354+
values += [
355+
"LLVM_NATIVE_ASMPARSER=",
356+
"LLVM_NATIVE_ASMPRINTER=",
357+
"LLVM_NATIVE_DISASSEMBLER=",
358+
"LLVM_NATIVE_TARGET=",
359+
"LLVM_NATIVE_TARGETINFO=",
360+
"LLVM_NATIVE_TARGETMC=",
361+
"LLVM_NATIVE_TARGETMCA=",
362+
]
363+
}
364+
350365
if (current_os == "win") {
351366
values += [
352367
"HAVE_SYSEXITS_H=",

llvm/utils/gn/secondary/llvm/lib/Target/targets.gni

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ llvm_all_targets = [
2626
"X86",
2727
]
2828

29+
# FIXME: This should be based off target_cpu once cross compiles work.
30+
if (host_cpu == "arm64") {
31+
native_target = "AArch64"
32+
} else if (host_cpu == "arm") {
33+
native_target = "ARM"
34+
} else if (host_cpu == "ppc" || host_cpu == "ppc64") {
35+
native_target = "PowerPC"
36+
} else if (host_cpu == "x86" || host_cpu == "x64") {
37+
native_target = "X86"
38+
} else {
39+
assert(false, "add your host_cpu above")
40+
}
41+
2942
if (llvm_targets_to_build == "host") {
30-
if (host_cpu == "arm64") {
31-
llvm_targets_to_build = [ "AArch64" ]
32-
} else if (host_cpu == "arm") {
33-
llvm_targets_to_build = [ "ARM" ]
34-
} else if (host_cpu == "ppc" || host_cpu == "ppc64") {
35-
llvm_targets_to_build = [ "PowerPC" ]
36-
} else if (host_cpu == "x86" || host_cpu == "x64") {
37-
llvm_targets_to_build = [ "X86" ]
38-
} else {
39-
assert(false, "add your host_cpu above")
40-
}
43+
llvm_targets_to_build = [ native_target ]
4144
} else if (llvm_targets_to_build == "all") {
4245
llvm_targets_to_build = llvm_all_targets
4346
}
@@ -54,7 +57,11 @@ llvm_build_PowerPC = false
5457
llvm_build_SystemZ = false
5558
llvm_build_WebAssembly = false
5659
llvm_build_X86 = false
60+
llvm_build_native = false
5761
foreach(target, llvm_targets_to_build) {
62+
if (target == native_target) {
63+
llvm_build_native = true
64+
}
5865
if (target == "AArch64") {
5966
llvm_build_AArch64 = true
6067
} else if (target == "AMDGPU") {
@@ -87,19 +94,6 @@ foreach(target, llvm_targets_to_build) {
8794
}
8895
}
8996

90-
# FIXME: This should be based off target_cpu once cross compiles work.
91-
if (host_cpu == "arm64") {
92-
native_target = "AArch64"
93-
} else if (host_cpu == "arm") {
94-
native_target = "ARM"
95-
} else if (host_cpu == "ppc" || host_cpu == "ppc64") {
96-
native_target = "PowerPC"
97-
} else if (host_cpu == "x86" || host_cpu == "x64") {
98-
native_target = "X86"
99-
} else {
100-
assert(false, "Unsuppored host_cpu '$host_cpu'.")
101-
}
102-
10397
supported_android_toolchains = []
10498

10599
if (android_ndk_path != "") {

0 commit comments

Comments
 (0)