Skip to content

Commit a81abd5

Browse files
authored
LLVM crosscompile x64 for ARM64 (#1826)
* LLVM crosscompile x64 for ARM64 * Fix MacOS host platform test * Ensure options is persistent in cross compile paths
1 parent 1d1b21f commit a81abd5

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

build/llvm/LLVM.lua

+34
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,44 @@ function build_llvm(llvm_build)
438438
local options = os.ishost("macosx") and
439439
"-DLLVM_ENABLE_LIBCXX=true" or ""
440440
local is32bits = target_architecture() == "x86"
441+
local targetIsArm64 = target_architecture() == "arm64"
442+
441443
if is32bits then
442444
options = options .. (is32bits and " -DLLVM_BUILD_32_BITS=true" or "")
443445
end
444446

447+
if targetIsArm64 then
448+
if os.host() == "linux" then
449+
local host_arch = unix_host_architecture()
450+
if host_arch ~= "aarch64" then
451+
options = options .. ""
452+
.. ' -DCMAKE_SYSTEM_NAME=Linux'
453+
.. ' -DCMAKE_SYSTEM_PROCESSOR=aarch64'
454+
.. ' -DCMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc'
455+
.. ' -DCMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++'
456+
.. ' -DCMAKE_ASM_COMPILER=/usr/bin/aarch64-linux-gnu-as'
457+
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER'
458+
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY'
459+
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY'
460+
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY'
461+
.. ' ' .. options
462+
end
463+
end
464+
if os.host() == "macosx" then
465+
local host_arch = unix_host_architecture()
466+
if host_arch ~= "arm64" then
467+
options = options .. ""
468+
.. ' -DCMAKE_SYSTEM_NAME=Darwin'
469+
.. ' -DCMAKE_SYSTEM_PROCESSOR=arm64'
470+
.. ' -DCMAKE_C_COMPILER_TARGET=arm64-apple-darwin21.6.0'
471+
.. ' -DCMAKE_CXX_COMPILER_TARGET=arm64-apple-darwin21.6.0'
472+
.. ' -DCMAKE_ASM_COMPILER_TARGET=arm64-apple-darwin21.6.0'
473+
.. ' ' .. options
474+
end
475+
end
476+
end
477+
478+
445479
cmake("Ninja", conf, llvm_build, options)
446480
ninja('"' .. llvm_build .. '"')
447481
ninja('"' .. llvm_build .. '"', "clang-headers")

build/scripts/Utils.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ function download(url, file, try)
112112
return res, code
113113
end
114114

115+
function unix_host_architecture()
116+
result, errorCode = os.outputof("uname -m")
117+
return result
118+
end
119+
115120
--
116121
-- Allows copying directories.
117122
-- It uses the premake patterns (**=recursive match, *=file match)
@@ -202,4 +207,4 @@ function os.rmfiles(src_dir, filter)
202207
print( "Error: " .. counter .. "/" .. #matches .. " files removed.")
203208
return nil
204209
end
205-
end
210+
end

0 commit comments

Comments
 (0)