From 7c07d3f22706ab71922e48d02f66b498dd37fa59 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Thu, 26 Jan 2023 11:42:54 +0800 Subject: [PATCH] add multi-architecture support for MacOS --- bin/README.md | 20 ++++++++++++++++++++ bin/README_EN.md | 20 ++++++++++++++++++++ bin/builders/MacBuilder.ts | 19 ++++++++++++++----- bin/cli.ts | 3 ++- bin/defaults.ts | 1 + bin/types.ts | 3 +++ dist/cli.js | 23 +++++++++++++++++++---- 7 files changed, 79 insertions(+), 10 deletions(-) diff --git a/bin/README.md b/bin/README.md index 3cbe44c..9a16cba 100644 --- a/bin/README.md +++ b/bin/README.md @@ -124,3 +124,23 @@ url 为你需要打包的网页链接 🔗,必须提供。 # 或者 -f ``` + +#### [multi-arch] +打包结果同时支持英特尔和m1芯片,仅适用于MacOS,默认为 `false`。 + +##### 准备工作 +- 注意:开启该选项后,需要用rust官网的rustup安装rust,不支持brew安装。 +- 对于intel芯片用户,需要安装arm64跨平台包,使安装包支持m1芯片,使用下面命令安装。 +```shell +rustup target add aarch64-apple-darwin +``` +- 对于M1芯片用户,需要安装x86跨平台包,使安装包支持interl芯片,使用下面的命令安装。 +```shell +rustup target add x86_64-apple-darwin +``` +##### 使用方法 +```shell +--multi-arch +# 或者 +-m +``` \ No newline at end of file diff --git a/bin/README_EN.md b/bin/README_EN.md index 30dd938..74a385b 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -123,3 +123,23 @@ Indicates if the window should be full screen on application launch. The default # or -f ``` + +#### [multi-arch] +Package results support both Intel and m1 chips, only for MacOS. The default is `false`. + +##### Preparation +- Note: After enabling this option, you need to use rustup on the rust official website to install rust, brew installation is not supported. +- For intel chip users, you need to install the arm64 cross-platform package to make the installation package support the m1 chip, and use the following command to install. +```shell +rustup target add aarch64-apple-darwin +``` +- For M1 chip users, you need to install the x86 cross-platform package to make the installation package support the interl chip, and use the following command to install. +```shell +rustup target add x86_64-apple-darwin +``` +##### Instructions +```shell +--multi-arch +# or +-m +``` diff --git a/bin/builders/MacBuilder.ts b/bin/builders/MacBuilder.ts index 4fedbc7..c0422f3 100644 --- a/bin/builders/MacBuilder.ts +++ b/bin/builders/MacBuilder.ts @@ -39,11 +39,20 @@ export default class MacBuilder implements IBuilder { const { name } = options; await mergeTauriConfig(url, options, tauriConf); - - //这里直接使用 universal-apple-darwin 的打包,而非当前系统的包 - await shellExec(`cd ${npmDirectory} && npm install && npm run build:mac`); - - const dmgName = `${name}_${tauriConf.package.version}_universal.dmg`; + let dmgName: string; + if (options.multi_arch) { + await shellExec(`cd ${npmDirectory} && npm install && npm run build:mac`); + dmgName = `${name}_${tauriConf.package.version}_universal.dmg`; + } else { + await shellExec(`cd ${npmDirectory} && npm install && npm run build`); + let arch: string; + if (process.arch === "x64") { + arch = "amd64"; + } else { + arch = process.arch; + } + dmgName = `${name}_${tauriConf.package.version}_${arch}.deb`; + } const appPath = this.getBuildAppPath(npmDirectory, dmgName); const distPath = path.resolve(`${name}.dmg`); await fs.copyFile(appPath, distPath); diff --git a/bin/cli.ts b/bin/cli.ts index f4e946d..b68ef5d 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -21,7 +21,8 @@ program .option('--no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable) .option('-f, --fullscreen', 'makes the packaged app start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen) .option('-t, --transparent', 'transparent title bar', DEFAULT_PAKE_OPTIONS.transparent) - .option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) + .option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.debug) + .option('-m, --multi-arch', "Supports both Intel and m1 chips, only for Mac.", DEFAULT_PAKE_OPTIONS.multi_arch) .action(async (url: string, options: PakeCliOptions) => { await checkUpdateTips(); diff --git a/bin/defaults.ts b/bin/defaults.ts index fb5cbff..db801ca 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -8,6 +8,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { resizable: true, transparent: false, debug: false, + multi_arch: false, }; export const DEFAULT_APP_NAME = 'Pake'; diff --git a/bin/types.ts b/bin/types.ts index 9610edb..7431d88 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -22,6 +22,9 @@ export interface PakeCliOptions { /** 调试模式,会输出更多日志 */ debug: boolean; + + /** mutli arch, Supports both Intel and m1 chips, only for Mac */ + multi_arch: boolean; } export interface PakeAppOptions extends PakeCliOptions { diff --git a/dist/cli.js b/dist/cli.js index c304968..1321e1e 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -48,6 +48,7 @@ const DEFAULT_PAKE_OPTIONS = { resizable: true, transparent: false, debug: false, + multi_arch: false, }; const tlds = [ @@ -2016,9 +2017,22 @@ class MacBuilder { log.debug('PakeAppOptions', options); const { name } = options; yield mergeTauriConfig(url, options, tauriConf); - //这里直接使用 universal-apple-darwin 的打包,而非当前系统的包 - yield shellExec(`cd ${npmDirectory} && npm install && npm run build:mac`); - const dmgName = `${name}_${tauriConf.package.version}_universal.dmg`; + let dmgName; + if (options.multi_arch) { + yield shellExec(`cd ${npmDirectory} && npm install && npm run build:mac`); + dmgName = `${name}_${tauriConf.package.version}_universal.dmg`; + } + else { + yield shellExec(`cd ${npmDirectory} && npm install && npm run build`); + let arch; + if (process.arch === "x64") { + arch = "amd64"; + } + else { + arch = process.arch; + } + dmgName = `${name}_${tauriConf.package.version}_${arch}.deb`; + } const appPath = this.getBuildAppPath(npmDirectory, dmgName); const distPath = path.resolve(`${name}.dmg`); yield fs.copyFile(appPath, distPath); @@ -2263,7 +2277,8 @@ program .option('--no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable) .option('-f, --fullscreen', 'makes the packaged app start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen) .option('-t, --transparent', 'transparent title bar', DEFAULT_PAKE_OPTIONS.transparent) - .option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) + .option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.debug) + .option('-m, --multi-arch', "Supports both Intel and m1 chips, only for Mac.", DEFAULT_PAKE_OPTIONS.multi_arch) .action((url, options) => __awaiter(void 0, void 0, void 0, function* () { yield checkUpdateTips(); if (!url) {