Browse Source

Build changes.

- Added support for building with Clang and LLD
- Switched to use csc.exe Roslyn compiler under Mono
- Disable most of the support for explicit pre-C++11 ABI since we do not
need it anymore
typeloc_clang
Joao Matos 7 years ago committed by João Matos
parent
commit
4fcfe4e4eb
  1. 32
      build/Helpers.lua
  2. 1
      build/LLVM.lua
  3. 3
      build/Tests.lua
  4. 1
      build/premake5.lua
  5. 19
      build/scripts/ClangToolset.cmake
  6. 47
      build/scripts/LLVM.lua
  7. 7
      src/CppParser/Bootstrap/Bootstrap.cs
  8. 6
      src/CppParser/Bootstrap/premake5.lua
  9. 2
      src/Parser/premake5.lua

32
build/Helpers.lua

@ -12,7 +12,7 @@ newoption {
newoption { newoption {
trigger = "no-cxx11-abi", trigger = "no-cxx11-abi",
description = "disable cxx11 abi on gcc 4.9+" description = "disable C++-11 ABI on GCC 4.9+"
} }
explicit_target_architecture = _OPTIONS["arch"] explicit_target_architecture = _OPTIONS["arch"]
@ -40,7 +40,15 @@ if not _OPTIONS["arch"] then
_OPTIONS["arch"] = target_architecture() _OPTIONS["arch"] = target_architecture()
end end
action = _ACTION or "" -- Uncomment to enable Roslyn compiler.
--[[
premake.override(premake.tools.dotnet, "gettoolname", function(base, cfg, tool)
if tool == "csc" then
return "csc"
end
return base(cfg, tool)
end)
]]
basedir = path.getdirectory(_PREMAKE_COMMAND) basedir = path.getdirectory(_PREMAKE_COMMAND)
depsdir = path.getabsolute("../deps"); depsdir = path.getabsolute("../deps");
@ -50,7 +58,7 @@ bindir = path.getabsolute("../bin");
examplesdir = path.getabsolute("../examples"); examplesdir = path.getabsolute("../examples");
testsdir = path.getabsolute("../tests"); testsdir = path.getabsolute("../tests");
builddir = path.getabsolute("./" .. action); builddir = path.getabsolute("./" .. _ACTION);
if _ARGS[1] then if _ARGS[1] then
builddir = path.getabsolute("./" .. _ARGS[1]); builddir = path.getabsolute("./" .. _ARGS[1]);
end end
@ -72,6 +80,7 @@ msvc_cpp_defines = { }
generate_build_config = true generate_build_config = true
function string.starts(str, start) function string.starts(str, start)
if str == nil then return end
return string.sub(str, 1, string.len(start)) == start return string.sub(str, 1, string.len(start)) == start
end end
@ -99,6 +108,9 @@ function SetupNativeProject()
buildoptions { gcc_buildflags } buildoptions { gcc_buildflags }
links { "stdc++" } links { "stdc++" }
filter { "toolset:clang", "system:not macosx" }
linkoptions { "-fuse-ld=/usr/bin/ld.lld" }
filter { "system:macosx", "language:C++" } filter { "system:macosx", "language:C++" }
buildoptions { gcc_buildflags, "-stdlib=libc++" } buildoptions { gcc_buildflags, "-stdlib=libc++" }
links { "c++" } links { "c++" }
@ -116,12 +128,6 @@ function SetupNativeProject()
systemversion("latest") systemversion("latest")
filter {} filter {}
if os.istarget("linux") then
if not UseCxx11ABI() then
defines { "_GLIBCXX_USE_CXX11_ABI=0" }
end
end
end end
function SetupManagedProject() function SetupManagedProject()
@ -195,6 +201,11 @@ function StaticLinksOpt(libnames)
links(existing_libnames) links(existing_libnames)
end end
function UseClang()
local compiler = os.getenv("CXX")
return string.match(compiler, "clang")
end
function GccVersion() function GccVersion()
local compiler = os.getenv("CXX") local compiler = os.getenv("CXX")
if compiler == nil then if compiler == nil then
@ -202,6 +213,9 @@ function GccVersion()
end end
local out = os.outputof(compiler.." -v") local out = os.outputof(compiler.." -v")
local version = string.match(out, "gcc version [0-9\\.]+") local version = string.match(out, "gcc version [0-9\\.]+")
if version == nil then
version = string.match(out, "clang version [0-9\\.]+")
end
return string.sub(version, 13) return string.sub(version, 13)
end end

1
build/LLVM.lua

@ -10,6 +10,7 @@ local LLVMRootDirRelease = ""
require "scripts/LLVM" require "scripts/LLVM"
function SearchLLVM() function SearchLLVM()
local basedir = path.getdirectory(_PREMAKE_COMMAND)
LLVMRootDirDebug = basedir .. "/scripts/" .. get_llvm_package_name(nil, "Debug") LLVMRootDirDebug = basedir .. "/scripts/" .. get_llvm_package_name(nil, "Debug")
LLVMRootDirRelease = basedir .. "/scripts/" .. get_llvm_package_name() LLVMRootDirRelease = basedir .. "/scripts/" .. get_llvm_package_name()

3
build/Tests.lua

@ -190,6 +190,9 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
LinkNUnit() LinkNUnit()
links { "CppSharp.Runtime" } links { "CppSharp.Runtime" }
filter { "action:netcore" }
dotnetframework "netcoreapp2.0"
end end
function SetupTestProjectsCLI(name, extraFiles, suffix) function SetupTestProjectsCLI(name, extraFiles, suffix)

1
build/premake5.lua

@ -30,6 +30,7 @@ solution "CppSharp"
include (srcdir .. "/AST") include (srcdir .. "/AST")
include (srcdir .. "/CppParser") include (srcdir .. "/CppParser")
include (srcdir .. "/CppParser/Bindings") include (srcdir .. "/CppParser/Bindings")
include (srcdir .. "/CppParser/Bootstrap")
include (srcdir .. "/CppParser/ParserGen") include (srcdir .. "/CppParser/ParserGen")
include (srcdir .. "/Parser") include (srcdir .. "/Parser")
include (srcdir .. "/CLI") include (srcdir .. "/CLI")

19
build/scripts/ClangToolset.cmake

@ -0,0 +1,19 @@
SET (CMAKE_C_COMPILER "/usr/bin/clang")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-glldb")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -glldb")
SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
SET (CMAKE_CXX_FLAGS "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG "-glldb")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -glldb")
SET (CMAKE_AR "/usr/bin/llvm-ar")
SET (CMAKE_LINKER "/usr/bin/llvm-ld")
SET (CMAKE_NM "/usr/bin/llvm-nm")
SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib")

47
build/scripts/LLVM.lua

@ -2,6 +2,7 @@ require "Build"
require "Utils" require "Utils"
require "../Helpers" require "../Helpers"
local basedir = path.getdirectory(_PREMAKE_COMMAND)
local llvm = path.getabsolute(basedir .. "/../deps/llvm") local llvm = path.getabsolute(basedir .. "/../deps/llvm")
-- Prevent premake from inserting /usr/lib64 search path on linux. GCC does not need this path specified -- Prevent premake from inserting /usr/lib64 search path on linux. GCC does not need this path specified
@ -112,15 +113,19 @@ function get_llvm_package_name(rev, conf, arch)
local toolset = get_toolset_configuration_name(arch) local toolset = get_toolset_configuration_name(arch)
table.insert(components, toolset) table.insert(components, toolset)
if os.istarget("linux") then if os.istarget("linux") then
local version = GccVersion() if UseClang() then
if version < "5.0.0" then table.insert(components, "clang")
-- Minor version matters only with gcc 4.8/4.9 else
version = string.match(version, "%d+.%d+") local version = GccVersion()
else if version < "5.0.0" then
version = string.match(version, "%d+") -- Minor version matters only with gcc 4.8/4.9
end version = string.match(version, "%d+.%d+")
table.insert(components, "gcc-"..version) else
version = string.match(version, "%d+")
end
table.insert(components, "gcc-"..version)
end
end end
if not conf then if not conf then
@ -129,12 +134,6 @@ function get_llvm_package_name(rev, conf, arch)
table.insert(components, conf) table.insert(components, conf)
if os.istarget("linux") then
if GccVersion() >= "4.9.0" and not UseCxx11ABI() then
table.insert(components, "no-cxx11")
end
end
return table.concat(components, "-") return table.concat(components, "-")
end end
@ -216,14 +215,14 @@ function cmake(gen, conf, builddir, options)
if options == nil then if options == nil then
options = "" options = ""
end end
if not UseCxx11ABI() then
options = options.." -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0'" if UseClang() then
local cmake = path.join(basedir, "scripts", "ClangToolset.cmake")
options = options .. " -DLLVM_USE_LINKER=/usr/bin/ld.lld"
end end
local cmd = cmake .. " -G " .. '"' .. gen .. '"' local cmd = cmake .. " -G " .. '"' .. gen .. '"'
.. ' -DCLANG_BUILD_TOOLS=false' .. ' -DCLANG_BUILD_TOOLS=false'
.. ' -DCLANG_INSTALL_SCANBUILD=false'
.. ' -DCLANG_INSTALL_SCANVIEW=false'
.. ' -DCLANG_TOOL_CLANG_DIFF_BUILD=false' .. ' -DCLANG_TOOL_CLANG_DIFF_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_FUNC_MAPPING_BUILD=false' .. ' -DCLANG_TOOL_CLANG_FUNC_MAPPING_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=false' .. ' -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=false'
@ -231,9 +230,9 @@ function cmake(gen, conf, builddir, options)
.. ' -DCLANG_TOOL_CLANG_REFACTOR_BUILD=false' .. ' -DCLANG_TOOL_CLANG_REFACTOR_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_RENAME_BUILD=false' .. ' -DCLANG_TOOL_CLANG_RENAME_BUILD=false'
.. ' -DCLANG_TOOL_DRIVER_BUILD=false' .. ' -DCLANG_TOOL_DRIVER_BUILD=false'
.. ' -DCLANG_TOOL_HANDLE_CXX_BUILD=false' .. ' -DLLVM_BUILD_TOOLS=false'
.. ' -DCLANG_TOOL_HANDLE_LLVM_BUILD=false' .. ' -DLLVM_ENABLE_DUMP=true'
.. ' -DLLVM_BUILD_TOOLS=false' .. ' -DLLVM_ENABLE_DUMP=true'
.. ' -DLLVM_ENABLE_LIBEDIT=false' .. ' -DLLVM_ENABLE_LIBEDIT=false'
.. ' -DLLVM_ENABLE_ZLIB=false' .. ' -DLLVM_ENABLE_ZLIB=false'
.. ' -DLLVM_ENABLE_TERMINFO=false' .. ' -DLLVM_ENABLE_TERMINFO=false'
@ -278,12 +277,10 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_LINK_BUILD=false' .. ' -DLLVM_TOOL_LLVM_LINK_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_LTO_BUILD=false' .. ' -DLLVM_TOOL_LLVM_LTO_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_LTO2_BUILD=false' .. ' -DLLVM_TOOL_LLVM_LTO2_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MCMARKUP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_ASSEMBLE_FUZZER_BUILD=false' .. ' -DLLVM_TOOL_LLVM_MC_ASSEMBLE_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_BUILD=false' .. ' -DLLVM_TOOL_LLVM_MC_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_DISASSEMBLE_FUZZER_BUILD=false' .. ' -DLLVM_TOOL_LLVM_MC_DISASSEMBLE_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MCA_BUILD=false' .. ' -DLLVM_TOOL_LLVM_MCA_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MODEXTRACT_BUILD=false' .. ' -DLLVM_TOOL_LLVM_MODEXTRACT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MT_BUILD=false' .. ' -DLLVM_TOOL_LLVM_MT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_NM_BUILD=false' .. ' -DLLVM_TOOL_LLVM_NM_BUILD=false'
@ -291,7 +288,6 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_OBJDUMP_BUILD=false' .. ' -DLLVM_TOOL_LLVM_OBJDUMP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=false' .. ' -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=false' .. ' -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PDBDUMP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false' .. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PROFDATA_BUILD=false' .. ' -DLLVM_TOOL_LLVM_PROFDATA_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false' .. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false'
@ -308,7 +304,6 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_UNDNAME_BUILD=false' .. ' -DLLVM_TOOL_LLVM_UNDNAME_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_XRAY_BUILD=false' .. ' -DLLVM_TOOL_LLVM_XRAY_BUILD=false'
.. ' -DLLVM_TOOL_LTO_BUILD=false' .. ' -DLLVM_TOOL_LTO_BUILD=false'
.. ' -DLLVM_TOOL_MSBUILD_BUILD=false'
.. ' -DLLVM_TOOL_OBJ2YAML_BUILD=false' .. ' -DLLVM_TOOL_OBJ2YAML_BUILD=false'
.. ' -DLLVM_TOOL_OPT_BUILD=false' .. ' -DLLVM_TOOL_OPT_BUILD=false'
.. ' -DLLVM_TOOL_OPT_VIEWER_BUILD=false' .. ' -DLLVM_TOOL_OPT_VIEWER_BUILD=false'

7
src/CppParser/Bootstrap/Bootstrap.cs

@ -19,8 +19,7 @@ namespace CppSharp
{ {
var path = Path.Combine(directory.FullName, dir); var path = Path.Combine(directory.FullName, dir);
if (Directory.Exists(path) && if (Directory.Exists(path))
Directory.Exists(Path.Combine(directory.FullName, "patches")))
return path; return path;
directory = directory.Parent; directory = directory.Parent;
@ -33,9 +32,7 @@ namespace CppSharp
{ {
driver.Options.GeneratorKind = GeneratorKind.CSharp; driver.Options.GeneratorKind = GeneratorKind.CSharp;
driver.Options.DryRun = true; driver.Options.DryRun = true;
driver.ParserOptions.SetupXcode(); driver.ParserOptions.Setup();
driver.ParserOptions.MicrosoftMode = false;
driver.ParserOptions.TargetTriple = "i686-apple-darwin12.4.0";
var module = driver.Options.AddModule("CppSharp"); var module = driver.Options.AddModule("CppSharp");

6
src/CppParser/Bootstrap/premake5.lua

@ -7,7 +7,9 @@ project "CppSharp.Parser.Bootstrap"
debugdir "." debugdir "."
files { "Bootstrap.cs", "*.lua" } files { "Bootstrap.cs", "*.lua" }
links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "System", "System.Core" } links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "CppSharp.Parser" }
filter { "action:not netcore" }
links { "System", "System.Core" }
SetupParser() SetupParser()

2
src/Parser/premake5.lua

@ -11,7 +11,7 @@ local function GenerateBuildConfig()
file:close() file:close()
end end
if generate_build_config == true then if generate_build_config == true and _ACTION then
GenerateBuildConfig() GenerateBuildConfig()
end end

Loading…
Cancel
Save