Skip to content

Commit 0334d50

Browse files
committed
LLVM crosscompile x64 for ARM64
1 parent 1d1b21f commit 0334d50

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

build/llvm/LLVM.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ function build_llvm(llvm_build)
423423

424424
os.mkdir(llvm_build)
425425

426+
print("starting llvm build process... " .. target_architecture())
426427
local conf = get_llvm_configuration_name()
427428
local use_msbuild = true
428429
if os.ishost("windows") and use_msbuild then
@@ -438,10 +439,46 @@ function build_llvm(llvm_build)
438439
local options = os.ishost("macosx") and
439440
"-DLLVM_ENABLE_LIBCXX=true" or ""
440441
local is32bits = target_architecture() == "x86"
442+
local targetIsArm64 = target_architecture() == "arm64"
443+
441444
if is32bits then
442445
options = options .. (is32bits and " -DLLVM_BUILD_32_BITS=true" or "")
443446
end
444447

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

build/scripts/Utils.lua

Lines changed: 6 additions & 1 deletion
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)