From e08d022e2febdd691354028c6811986c62b75b43 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Fri, 19 Aug 2022 13:43:37 +0200 Subject: [PATCH] Cross-compile MacOS launcher on x86_64 and aarch64 --- app_bundler/lib/app_bundler/macos.ex | 40 +++++++++++++++++++--------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/app_bundler/lib/app_bundler/macos.ex b/app_bundler/lib/app_bundler/macos.ex index 7d006b957..f7dcad6cc 100644 --- a/app_bundler/lib/app_bundler/macos.ex +++ b/app_bundler/lib/app_bundler/macos.ex @@ -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