diff --git a/build/scripts/Build.lua b/build/scripts/Build.lua index 71acb82f..eec669e9 100644 --- a/build/scripts/Build.lua +++ b/build/scripts/Build.lua @@ -25,5 +25,40 @@ function msbuild(sln, conf) execute(cmd) end +function premake(file, action) + -- search for file with extension Lua + if os.isfile(file .. ".lua") then + file = file .. ".lua" + end + + local cmd = string.format("%s --file=%s %s", _PREMAKE_COMMAND, file, action) + return execute(cmd) +end + +function build_cppsharp() + -- install dependencies + premake("Provision", "provision") + + -- if there is an llvm git clone then use it + -- otherwise download and extract llvm/clang build + + premake("LLVM", "download_llvm") + + -- generate project files + premake("../premake4", "gmake") + + -- build cppsharp + --[[BUILD_CONF=release_x32; + config=$BUILD_CONF make -C build/gmake/ + BUILD_DIR=`ls build/gmake/lib` + mkdir -p "$PWD"/build/gmake/lib/lib/"$BUILD_DIR" + cp "$PWD"/build/gmake/lib/"$BUILD_DIR"/libNamespacesBase.* "$PWD"/build/gmake/lib/lib/"$BUILD_DIR" + ]] +end + +if _ACTION == "build_cppsharp" then + build_cppsharp() + os.exit() +end diff --git a/build/scripts/Dependencies.lua b/build/scripts/Dependencies.lua index f2563f25..aaafcc23 100644 --- a/build/scripts/Dependencies.lua +++ b/build/scripts/Dependencies.lua @@ -15,13 +15,3 @@ if _ACTION == "nuget" then nuget() os.exit() end - -if _ACTION == "clone_llvm" then - clone_llvm() - os.exit() -end - -if _ACTION == "download_llvm" then - download_llvm() - os.exit() -end \ No newline at end of file diff --git a/build/scripts/LLVM.lua b/build/scripts/LLVM.lua index 61142a72..e2cf76f0 100644 --- a/build/scripts/LLVM.lua +++ b/build/scripts/LLVM.lua @@ -1,41 +1,75 @@ require "Build" require "Utils" -local llvm = "../../deps/llvm/" -local llvm_build = "../../deps/llvm/" .. os.get() +local llvm = "../../deps/llvm" + +-- If we are inside vagrant then clone and build LLVM outside the shared folder, +-- otherwise file I/O performance will be terrible. +if is_vagrant() then + llvm = "~/llvm" +end + +local llvm_build = llvm .. "/" .. os.get() function clone_llvm() - local llvm_release = cat("LLVM-commit") + local llvm_release = cat("../LLVM-commit") print("LLVM release: " .. llvm_release) - local clang_release = cat("Clang-commit") + local clang_release = cat("../Clang-commit") print("Clang release: " .. clang_release) + if os.isdir(llvm) and not os.isdir(llvm .. "/.git") then + error("LLVM directory is not a git repository.") + end + if not os.isdir(llvm) then git.clone(llvm, "http://llvm.org/git/llvm.git") - git.checkout(llvm, llvm_release) + else + git.reset_hard(llvm, "HEAD") + git.pull_rebase(llvm) end - - if not os.isdir(llvm .. "/tools/clang") then - git.clone(llvm .. "/tools/clang", "http://llvm.org/git/clang.git") - git.checkout(llvm .. "/tools/clang", clang_release) + + local clang = llvm .. "/tools/clang" + if not os.isdir(clang) then + git.clone(clang, "http://llvm.org/git/clang.git") + else + git.reset_hard(clang, "HEAD") + git.pull_rebase(clang) end + + git.reset_hard(llvm, llvm_release) + git.reset_hard(clang, clang_release) +end + +function get_llvm_package_name(rev, conf) + return table.concat({"llvm", rev, os.get(), conf}, "-") +end + +function extract_7z(archive, dest_dir) + return execute(string.format("7z x %s -o%s -y", archive, dest_dir), true) end function download_llvm() - if os.is("windows") then - http.download("https://dl.dropboxusercontent.com/u/194502/CppSharp/llvm_windows_x86.7z") + local base = "https://dl.dropboxusercontent.com/u/194502/CppSharp/llvm/" + local conf = os.is("windows") and "RelWithDebInfo" or "Release" + local rev = string.sub(cat("../LLVM-commit"), 0, 6) + local pkg_name = get_llvm_package_name(rev, conf) + local archive = pkg_name .. ".7z" + + -- check if we already have the file downloaded + if not os.isfile(archive) then + download(base .. archive, archive) end -- extract the package - execute("7z x llvm_windows_x86.7z -o%DEPS_PATH%\llvm -y > nul") + if not os.isdir(pkg_name) then + extract_7z(archive, pkg_name) + end end function cmake(gen, conf) - print(os.getcwd()) - print(llvm_build) + local cwd = os.getcwd() os.chdir(llvm_build) - print(os.getcwd()) local cmd = "cmake -G " .. '"' .. gen .. '"' .. ' -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false' .. ' -DCLANG_ENABLE_ARCMT=false -DCLANG_ENABLE_REWRITER=false -DCLANG_ENABLE_STATIC_ANALYZER=false' @@ -43,6 +77,7 @@ function cmake(gen, conf) .. ' -DLLVM_TARGETS_TO_BUILD="X86"' .. ' -DCMAKE_BUILD_TYPE=' .. conf .. ' ..' execute(cmd) + os.chdir(cwd) end function clean_llvm(llvm_build) @@ -64,7 +99,8 @@ function build_llvm(llvm_build) end function package_llvm(conf, llvm, llvm_build) - local out = "llvm-" .. os.get() .. "-" .. conf + local rev = string.sub(git.rev_parse(llvm, "HEAD"), 0, 6) + local out = get_llvm_package_name(rev, conf) if os.isdir(out) then os.rmdir(out) end os.mkdir(out) @@ -108,10 +144,27 @@ function package_llvm(conf, llvm, llvm_build) end function archive_llvm(dir) - execute("7z a " .. out .. ".7z " .. "./" .. out .. "/*") + execute("7z a " .. dir .. ".7z " .. "./" .. dir .. "/*") end -clean_llvm(llvm_build) -build_llvm(llvm_build) ---local out = package_llvm("RelWithDebInfo", llvm, llvm_build) ---archive_llvm(out) \ No newline at end of file +if _ACTION == "clone_llvm" then + clone_llvm() + os.exit() +end + +if _ACTION == "build_llvm" then + clean_llvm(llvm_build) + build_llvm(llvm_build) + os.exit() +end + +if _ACTION == "package_llvm" then + local pkg = package_llvm("RelWithDebInfo", llvm, llvm_build) + archive_llvm(pkg) + os.exit() +end + +if _ACTION == "download_llvm" then + download_llvm() + os.exit() +end diff --git a/build/scripts/Provision.lua b/build/scripts/Provision.lua index 06767644..40d5a4ad 100644 --- a/build/scripts/Provision.lua +++ b/build/scripts/Provision.lua @@ -45,5 +45,54 @@ function download_cmake() end end -download_ninja() -download_cmake() \ No newline at end of file +local compile_llvm = is_vagrant() + +function provision_linux() + -- Add Repos + sudo("apt-key adv --keyserver http:////keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF") + sudo("echo \"deb http:////download.mono-project.com/repo/debian wheezy main\" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list") + + if is_vagrant() then + sudo("add-apt-repository -y ppa:george-edison55/cmake-3.x") + end + + sudo("apt-get update") + + -- Build tools + sudo("apt-get install -y git build-essential clang") + + sudo("apt-get install -y p7zip-full") + + -- Mono + sudo("apt-get install -y mono-devel") + + -- LLVM/Clang build tools + if compile_llvm then + sudo("apt-get install -y cmake ninja-build") + end +end + +function brew_install(pkg) + -- check if package is already installed + local res = os.outputof("brew ls --versions " .. pkg) + if string.is_empty(res) then + execute("brew install " .. pkg) + end +end + +function provision_osx() + brew_install("p7zip") + + if compile_llvm then + execute("brew cask install virtualbox vagrant") + end +end + +if _ACTION == "provision" then + if os.is("linux") then + provision_linux() + elseif os.is("macosx") then + provision_osx() + end + os.exit() +end diff --git a/build/scripts/Provision.sh b/build/scripts/Provision.sh deleted file mode 100644 index 1a91855c..00000000 --- a/build/scripts/Provision.sh +++ /dev/null @@ -1,14 +0,0 @@ -# Add Repos -apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF -echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list - -add-apt-repository ppa:george-edison55/cmake-3.x -apt-get update - -# Build tools -apt-get install -y git build-essential clang cmake ninja-build - -apt-get install -y p7zip-full - -# Mono -apt-get install -y mono-devel \ No newline at end of file diff --git a/build/scripts/UploadDropbox.sh b/build/scripts/UploadDropbox.sh deleted file mode 100644 index 60ac810c..00000000 --- a/build/scripts/UploadDropbox.sh +++ /dev/null @@ -1,9 +0,0 @@ - curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh - - echo APPKEY= > ~/.dropbox_uploader - echo APPSECRET= >> ~/.dropbox_uploader - echo ACCESS_LEVEL=sandbox >> ~/.dropbox_uploader - echo OAUTH_ACCESS_TOKEN= >> ~/.dropbox_uploader - echo OAUTH_ACCESS_TOKEN_SECRET= >> ~/.dropbox_uploader - - ./dropbox_uploader.sh upload llvm_linux_x86_64.7z llvm_linux_x86_64.7z \ No newline at end of file diff --git a/build/scripts/Utils.lua b/build/scripts/Utils.lua index d12bbff4..e20fbc00 100644 --- a/build/scripts/Utils.lua +++ b/build/scripts/Utils.lua @@ -1,3 +1,7 @@ +function string.is_empty(s) + return not s or s == '' +end + function cat(file) local file = assert(io.open(file, "r")) local output = file:read('*all') @@ -5,32 +9,57 @@ function cat(file) return output end -function execute(cmd) +function execute(cmd, quiet) print(cmd) - local file = assert(io.popen(cmd, "r")) - local output = file:read('*all') - file:close() - return output + if not quiet then + return os.execute(cmd) + else + local file = assert(io.popen(cmd .. " 2>&1", "r")) + local output = file:read('*all') + file:close() + return output + end +end + +function sudo(cmd) + return os.execute("sudo " .. cmd) +end + +function is_vagrant() + return os.isdir("/home/vagrant") end -local git = {} +git = {} + +-- Remove once https://github.com/premake/premake-core/pull/307 is merged. +local sep = os.is("windows") and "\\" or "/" function git.clone(dir, url, target) - local cmd = "git clone " .. url .. " " .. path.translate(dir) + local cmd = "git clone " .. url .. " " .. path.translate(dir, sep) if target ~= nil then cmd = cmd .. " " .. target end - execute(cmd) + return execute(cmd) +end + +function git.pull_rebase(dir) + local cmd = "git -C " .. path.translate(dir, sep) .. " pull --rebase" + return execute(cmd) +end + +function git.reset_hard(dir, rev) + local cmd = "git -C " .. path.translate(dir, sep) .. " reset --hard " .. rev + return execute(cmd) end function git.checkout(dir, rev) - local cmd = "git -C " .. path.translate(dir) .. " checkout " .. rev - execute(cmd) + local cmd = "git -C " .. path.translate(dir, sep) .. " checkout " .. rev + return execute(cmd) end -function git.revision(dir) - local cmd = "git -C " .. path.translate(dir) .. " checkout " .. rev - execute(cmd) +function git.rev_parse(dir, rev) + local cmd = "git -C " .. path.translate(dir, sep) .. " rev-parse " .. rev + return os.outputof(cmd) end function http.progress (total, curr) @@ -42,12 +71,14 @@ function http.progress (total, curr) end function download(url, file) - print("Downloading file " .. file) + print("Downloading: " .. url) local res = http.download(url, file, http.progress) - if res == nil then - error("Error downloading file " .. file) + if res ~= "OK" then + os.remove(file) + error(res) end + return res end -- diff --git a/build/scripts/Vagrantfile b/build/scripts/Vagrantfile index 7824193f..b08a2bc1 100644 --- a/build/scripts/Vagrantfile +++ b/build/scripts/Vagrantfile @@ -4,6 +4,8 @@ $script = <