From d6049dc49ea5d93e67f852dad5f7af09ef952a13 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Wed, 5 Apr 2017 18:58:52 +0100 Subject: [PATCH] Added support for specifying build target architecture when building LLVM. Fixes https://github.com/mono/CppSharp/issues/694. --- build/scripts/LLVM.lua | 29 ++++++++++++++++++++++------- docs/BuildingLLVM.md | 4 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/build/scripts/LLVM.lua b/build/scripts/LLVM.lua index fb4f2b8c..7db358b9 100644 --- a/build/scripts/LLVM.lua +++ b/build/scripts/LLVM.lua @@ -2,6 +2,16 @@ require "Build" require "Utils" require "../Helpers" +newoption { + trigger = "arch", + value = "x86", + description = "Choose a particular architecture / bitness", + allowed = { + { "x86", "x86 32-bits" }, + { "x64", "x64 64-bits" }, + } +} + local llvm = path.getabsolute(basedir .. "/../deps/llvm") -- If we are inside vagrant then clone and build LLVM outside the shared folder, @@ -63,9 +73,10 @@ function get_vs_version() end function get_toolset_configuration_name() + local arch = _OPTIONS["arch"] + if os.is("windows") then local vsver = _ACTION - local arch = "x86" if not string.starts(vsver, "vs") then vsver = get_vs_version() @@ -74,7 +85,7 @@ function get_toolset_configuration_name() return table.concat({vsver, arch}, "-") end -- FIXME: Implement for non-Windows platforms - return nil + return table.concat({arch}, "-") end -- Returns a string describing the package configuration. @@ -85,10 +96,6 @@ function get_llvm_package_name(rev, conf, toolset) end rev = string.sub(rev, 0, 6) - if not conf then - conf = get_llvm_configuration_name() - end - if not toolset then toolset = get_toolset_configuration_name() end @@ -99,6 +106,10 @@ function get_llvm_package_name(rev, conf, toolset) table.insert(components, toolset) end + if not conf then + conf = get_llvm_configuration_name() + end + table.insert(components, conf) return table.concat(components, "-") @@ -277,7 +288,11 @@ function build_llvm(llvm_build) msbuild(llvm_sln, conf) else local options = os.is("macosx") and - "-DLLVM_ENABLE_LIBCXX=true -DLLVM_BUILD_32_BITS=true" or "" + "-DLLVM_ENABLE_LIBCXX=true" or "" + local is32bits = _OPTIONS["arch"] == "x86" + if is32bits then + options = options .. is32bits and " -DLLVM_BUILD_32_BITS=true" or "" + end cmake("Ninja", conf, llvm_build, options) ninja(llvm_build) ninja(llvm_build, "clang-headers") diff --git a/docs/BuildingLLVM.md b/docs/BuildingLLVM.md index 23b6ec30..3a918a41 100644 --- a/docs/BuildingLLVM.md +++ b/docs/BuildingLLVM.md @@ -66,9 +66,9 @@ Before building, ensure cmake is installed under Applications/Cmake.app and Ninj ../premake5-osx --file=LLVM.lua package_llvm ``` -If the clone_llvm step fails, you can try to manually clone LLVM and Clang as explained above. You should still run clone_llvm to ensure that you are on the correct revision. +You can specify an `--arch=x86` or `--arch=x64` flag to the invocations above to specify an explicit build architecture. -The compile flags for cmake can be edited in `build/scripts/LLVM.lua`, e.g. if you need to build a 64-bit version. +If the clone_llvm step fails, you can try to manually clone LLVM and Clang as explained above. You should still run clone_llvm to ensure that you are on the correct revision. ## Compiling on Linux