Skip to content

LLVM crosscompile x64 for ARM64 #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions build/llvm/LLVM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,44 @@ function build_llvm(llvm_build)
local options = os.ishost("macosx") and
"-DLLVM_ENABLE_LIBCXX=true" or ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this configuration is being ignored by the lines below. Could be an issue unless this is not needed anymore.

local is32bits = target_architecture() == "x86"
local targetIsArm64 = target_architecture() == "arm64"

if is32bits then
options = options .. (is32bits and " -DLLVM_BUILD_32_BITS=true" or "")
end

if targetIsArm64 then
if os.host() == "linux" then
local host_arch = unix_host_architecture()
if host_arch ~= "aarch64" then
options = options .. ""
.. ' -DCMAKE_SYSTEM_NAME=Linux'
.. ' -DCMAKE_SYSTEM_PROCESSOR=aarch64'
.. ' -DCMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc'
.. ' -DCMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++'
.. ' -DCMAKE_ASM_COMPILER=/usr/bin/aarch64-linux-gnu-as'
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER'
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY'
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY'
.. ' -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY'
.. ' ' .. options
end
end
if os.host() == "macosx" then
local host_arch = unix_host_architecture()
if host_arch ~= "arm64" then
options = options .. ""
.. ' -DCMAKE_SYSTEM_NAME=Darwin'
.. ' -DCMAKE_SYSTEM_PROCESSOR=arm64'
.. ' -DCMAKE_C_COMPILER_TARGET=arm64-apple-darwin21.6.0'
.. ' -DCMAKE_CXX_COMPILER_TARGET=arm64-apple-darwin21.6.0'
.. ' -DCMAKE_ASM_COMPILER_TARGET=arm64-apple-darwin21.6.0'
.. ' ' .. options
end
end
end


cmake("Ninja", conf, llvm_build, options)
ninja('"' .. llvm_build .. '"')
ninja('"' .. llvm_build .. '"', "clang-headers")
Expand Down
7 changes: 6 additions & 1 deletion build/scripts/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function download(url, file, try)
return res, code
end

function unix_host_architecture()
result, errorCode = os.outputof("uname -m")
return result
end

--
-- Allows copying directories.
-- It uses the premake patterns (**=recursive match, *=file match)
Expand Down Expand Up @@ -202,4 +207,4 @@ function os.rmfiles(src_dir, filter)
print( "Error: " .. counter .. "/" .. #matches .. " files removed.")
return nil
end
end
end