aboutsummaryrefslogtreecommitdiff
path: root/scripts/bundle.lua
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2022-01-20 14:38:22 +0100
committerMartin Ridgers <[email protected]>2022-01-20 14:38:22 +0100
commit7d20859c10203cd89a55f269f264ad1451d3e89f (patch)
tree77115bdb78d0464dbee551701fd47f8244fb03e1 /scripts/bundle.lua
parentAn implementation of 'xmake bundle' for Linux (diff)
downloadzen-7d20859c10203cd89a55f269f264ad1451d3e89f.tar.xz
zen-7d20859c10203cd89a55f269f264ad1451d3e89f.zip
Moved bundle.lua to scripts/bundle.lua to keep root clean
Diffstat (limited to 'scripts/bundle.lua')
-rw-r--r--scripts/bundle.lua183
1 files changed, 183 insertions, 0 deletions
diff --git a/scripts/bundle.lua b/scripts/bundle.lua
new file mode 100644
index 000000000..f277ba3bc
--- /dev/null
+++ b/scripts/bundle.lua
@@ -0,0 +1,183 @@
+-- Copyright Epic Games, Inc. All Rights Reserved.
+
+--------------------------------------------------------------------------------
+local function _exec(cmd, ...)
+ print("--", cmd, ...)
+ local ret = os.execv(cmd, {...})
+ print()
+ return ret
+end
+
+--------------------------------------------------------------------------------
+local function _build(arch, debug, config_args)
+ variant = debug and "debug" or "release"
+ local ret = _exec(
+ "xmake",
+ "config",
+ "--yes",
+ "--clean",
+ "--mode="..variant,
+ "--arch="..arch,
+ config_args)
+ if ret > 0 then
+ raise("Failed to configure xmake")
+ end
+
+ ret = _exec("xmake", "clean", "--yes", "zenserver")
+ if ret > 0 then
+ raise("Clean failed")
+ end
+
+ ret = _exec("xmake", "build", "--yes", "zenserver")
+ if ret > 0 then
+ raise("Build failed")
+ end
+end
+
+--------------------------------------------------------------------------------
+local function _zip(zip_path, ...)
+ os.tryrm(zip_path)
+
+ import("detect.tools.find_7z")
+ local cmd = find_7z()
+ if cmd then
+ -- A ./ prefix makes 7z ignore the directory structure
+ input_paths = {}
+ for _, input_path in ipairs({...}) do
+ input_path = path.relative(input_path, ".")
+ if input_path:sub(2,2) ~= ":" then
+ input_path = "./"..input_path
+ end
+ table.insert(input_paths, input_path)
+ end
+
+ local ret = _exec("7z", "a", zip_path, table.unpack(input_paths))
+ if ret > 0 then
+ raise("Received error from 7z")
+ end
+ return
+ end
+ print("7z not found")
+
+ import("detect.tools.find_zip")
+ cmd = find_zip()
+ if cmd then
+ local ret = _exec("zip", "--junk-paths", zip_path, ...)
+ if ret > 0 then
+ raise("Received error from zip")
+ end
+ return
+ end
+ print("zip not found")
+
+ raise("Unable to find a suitable zip tool")
+end
+
+--------------------------------------------------------------------------------
+local function _find_vcpkg_binary(triple, port, binary)
+ import("detect.sdks.find_vcpkgdir")
+ local root_dir = find_vcpkgdir()
+ if root_dir == nil or root_dir == "" then
+ raise("Unable to find vcpkg root directory")
+ end
+
+ bin_path = root_dir.."/installed/"..triple.."/tools/"..port.."/"..binary
+ if not os.isfile(bin_path) then
+ raise("Unable to locate vcpkg tool "..bin_path)
+ end
+
+ return bin_path
+end
+
+--------------------------------------------------------------------------------
+local function main_windows()
+ import("core.base.option")
+
+ zip_path = "build/zenserver-win64.zip"
+ config_args = nil
+ if option.get("withtrace") then
+ zip_path = "build/zenserver-trace-win64.zip"
+ config_args = "--zentrace=yes"
+ end
+
+ _build("x64", false, config_args)
+
+ local crashpad_handler_path = _find_vcpkg_binary(
+ "x64-windows-static",
+ "sentry-native",
+ "crashpad_handler.exe")
+
+ _zip(
+ zip_path,
+ "build/windows/x64/release/zenserver.exe",
+ "build/windows/x64/release/zenserver.pdb",
+ crashpad_handler_path)
+end
+
+--------------------------------------------------------------------------------
+local function main_mac()
+ -- Build and universalify
+ _build("x86_64")
+ _build("arm64")
+
+ os.mkdir("build/macosx/universal/release/")
+ local ret = _exec(
+ "lipo",
+ "-create",
+ "-output", "build/macosx/universal/release/zenserver",
+ "build/macosx/x86_64/release/zenserver",
+ "build/macosx/arm64/release/zenserver"
+ )
+ if ret > 0 then
+ raise("Failed creating univeral binary")
+ end
+
+ -- At the time of writing vcpkg does not support sentry-native on arm64. Once
+ -- it does we can create a univeral binary for this. For now just bundle x64
+ local crashpad_handler_path = _find_vcpkg_binary(
+ "x64-osx",
+ "sentry-native",
+ "crashpad_handler")
+
+ -- Zip
+ _zip(
+ "build/zenserver-macos.zip",
+ "build/macosx/universal/release/zenserver",
+ crashpad_handler_path)
+end
+
+--------------------------------------------------------------------------------
+local function main_linux()
+ _build("x86_64")
+
+ -- Crashpad handler does not exist for Linux
+ local crashpad_handler_path = nil
+ --[[
+ local crashpad_handler_path = _find_vcpkg_binary(
+ "x64-linux",
+ "sentry-native",
+ "crashpad_handler")
+ --]]
+
+ _zip(
+ "build/zenserver-linux.zip",
+ "build/linux/x86_64/release/zenserver",
+ crashpad_handler_path)
+end
+
+--------------------------------------------------------------------------------
+function main()
+ if is_host("windows") then
+ return main_windows()
+ end
+
+ if is_host("mac") then
+ return main_mac()
+ end
+
+ if is_host("linux") then
+ return main_linux()
+ end
+
+ raise("'xmake bundle' not currently supported on this platform")
+end