Cross-compile MacOS launcher on x86_64 and aarch64

This commit is contained in:
Wojtek Mach 2022-08-19 13:43:37 +02:00
parent 8a6c8a8371
commit e08d022e2f

View file

@ -18,21 +18,45 @@ defmodule AppBundler.MacOS do
launcher_eex_path = Path.expand("#{@templates_path}/macos/Launcher.swift.eex")
launcher_src_path = "#{tmp_dir}/Launcher.swift"
launcher_x86_64_path = "#{tmp_dir}/#{app_name}Launcher-x86_64"
launcher_aarch64_path = "#{tmp_dir}/#{app_name}Launcher-aarch64"
launcher_bin_path = "#{contents_path}/MacOS/#{app_name}Launcher"
copy_template(launcher_eex_path, launcher_src_path, release: release, app_options: options)
File.mkdir!("#{contents_path}/MacOS")
log(:green, :creating, Path.relative_to_cwd(launcher_bin_path))
log(:green, :creating, launcher_x86_64_path)
cmd!("swiftc", [
"-warnings-as-errors",
"-target",
swiftc_target(),
"x86_64-apple-macosx10.15",
"-o",
launcher_bin_path,
launcher_x86_64_path,
launcher_src_path
])
log(:green, :creating, launcher_aarch64_path)
cmd!("swiftc", [
"-warnings-as-errors",
"-target",
"arm64-apple-macosx12",
"-o",
launcher_aarch64_path,
launcher_src_path
])
log(:green, :creating, Path.relative_to_cwd(launcher_bin_path))
cmd!("lipo", [
launcher_x86_64_path,
launcher_aarch64_path,
"-create",
"-output",
launcher_bin_path
])
icon_path =
Keyword.get(options, :icon_path, Application.app_dir(:wx, "examples/demo/erlang.png"))
@ -167,14 +191,4 @@ defmodule AppBundler.MacOS do
File.rm_rf!(dest_tmp_path)
end
end
defp swiftc_target do
case :erlang.system_info(:system_architecture) do
'x86_64' ++ _ ->
"x86_64-apple-macosx10.15"
'aarch64' ++ _ ->
"arm64-apple-macosx12"
end
end
end