diff --git a/.github/workflows/llvm.yml b/.github/workflows/llvm.yml index 87b31a6803..966cc16922 100644 --- a/.github/workflows/llvm.yml +++ b/.github/workflows/llvm.yml @@ -27,6 +27,10 @@ jobs: - uses: actions/checkout@v4 - uses: lukka/get-cmake@latest + - name: Install cross compilers + if: startsWith(matrix.config.os, 'ubuntu') && startsWith(matrix.config.platform, 'arm64') + run: sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu + - name: Clone LLVM shell: bash run: build/build.sh clone_llvm @@ -43,4 +47,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: llvm - path: build/llvm/llvm-*-*.* \ No newline at end of file + path: build/llvm/llvm-*-*.* diff --git a/build/llvm/LLVM.lua b/build/llvm/LLVM.lua index 015743965b..0a08c06191 100644 --- a/build/llvm/LLVM.lua +++ b/build/llvm/LLVM.lua @@ -438,10 +438,44 @@ function build_llvm(llvm_build) local options = os.ishost("macosx") and "-DLLVM_ENABLE_LIBCXX=true" or "" 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") diff --git a/build/scripts/Utils.lua b/build/scripts/Utils.lua index afccb4e731..0ec325cafd 100644 --- a/build/scripts/Utils.lua +++ b/build/scripts/Utils.lua @@ -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) @@ -202,4 +207,4 @@ function os.rmfiles(src_dir, filter) print( "Error: " .. counter .. "/" .. #matches .. " files removed.") return nil end -end \ No newline at end of file +end