From da615bb1c7a94ee5680e6dc6bb1e5a4fbcf95020 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Sat, 8 Apr 2023 11:18:48 +0800 Subject: [PATCH] Add the multi_arch parameter of the master branch to the pake-cli --- bin/README.md | 36 ++++++++++++++++++++++++++++++++++++ bin/README_EN.md | 36 ++++++++++++++++++++++++++++++++++++ bin/builders/MacBuilder.ts | 35 +++++++++++++++++++++-------------- bin/cli.ts | 8 +++++++- bin/defaults.ts | 1 + bin/types.ts | 3 +++ 6 files changed, 104 insertions(+), 15 deletions(-) diff --git a/bin/README.md b/bin/README.md index 8d4f99d..eac62df 100644 --- a/bin/README.md +++ b/bin/README.md @@ -128,4 +128,40 @@ url 为你需要打包的网页链接 🔗或者本地html文件,必须提供 ```shell --copy-iter-file +``` + + +#### [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 +``` + +#### [targets] + +选择输出的包格式,支持deb/appimage/all,如果选择all,则同时打包deb和appimage,该选项仅支持Linux,默认为`all`。 + +```shell +--targets xxx ``` \ No newline at end of file diff --git a/bin/README_EN.md b/bin/README_EN.md index 27d5321..62a9396 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -128,3 +128,39 @@ Recursive copy, when the url is a local file path, if this option is enabled, th ```shell --copy-iter-file ``` + + +#### [multi-arch] + +Package results support both Intel and m1 chips, only for MacOS. The default is `false`. + +```shell +--targets xxx +``` + +##### 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 +``` + +#### [targets] + +Select the output package format, support deb/appimage/all, if all is selected, deb and appimage will be packaged at the same time, this option only supports Linux, the default is `all`. diff --git a/bin/builders/MacBuilder.ts b/bin/builders/MacBuilder.ts index 8a5fdcb..6e06d28 100644 --- a/bin/builders/MacBuilder.ts +++ b/bin/builders/MacBuilder.ts @@ -39,16 +39,21 @@ export default class MacBuilder implements IBuilder { const { name } = options; await mergeTauriConfig(url, options, tauriConf); - - const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build`); - let arch = "x64"; - if (process.arch === "arm64") { - arch = "aarch64"; + let dmgName: string; + if (options.multiArch) { + await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build:mac`); + dmgName = `${name}_${tauriConf.package.version}_universal.dmg`; } else { - arch = process.arch; + await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build`); + let arch = "x64"; + if (process.arch === "arm64") { + arch = "aarch64"; + } else { + arch = process.arch; + } + dmgName = `${name}_${tauriConf.package.version}_${arch}.dmg`; } - const dmgName = `${name}_${tauriConf.package.version}_${arch}.dmg`; - const appPath = this.getBuildedAppPath(npmDirectory, dmgName); + const appPath = this.getBuildAppPath(npmDirectory, dmgName, options.multiArch); const distPath = path.resolve(`${name}.dmg`); await fs.copyFile(appPath, distPath); await fs.unlink(appPath); @@ -57,11 +62,13 @@ export default class MacBuilder implements IBuilder { logger.success('You can find the app installer in', distPath); } - getBuildedAppPath(npmDirectory: string, dmgName: string) { - return path.join( - npmDirectory, - 'src-tauri/target/release/bundle/dmg', - dmgName - ); + getBuildAppPath(npmDirectory: string, dmgName: string, multiArch: boolean) { + let dmgPath: string; + if (multiArch) { + dmgPath = 'src-tauri/target/universal-apple-darwin/release/bundle/dmg'; + } else { + dmgPath = 'src-tauri/target/release/bundle/dmg'; + } + return path.join(npmDirectory, dmgPath, dmgName); } } diff --git a/bin/cli.ts b/bin/cli.ts index 294a06b..35777a9 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -30,10 +30,16 @@ program .option('--iter-copy-file', 'copy all static file to pake app when url is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile) + .option( + '-m, --multi-arch', + "available for Mac only, and supports both Intel and M1", + DEFAULT_PAKE_OPTIONS.multiArch + ) .option( '--targets ', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', - DEFAULT_PAKE_OPTIONS.targets) + DEFAULT_PAKE_OPTIONS.targets + ) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action(async (url: string, options: PakeCliOptions) => { checkUpdateTips(); diff --git a/bin/defaults.ts b/bin/defaults.ts index 4200bb4..48e4972 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -10,6 +10,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { userAgent: '', showMenu: false, showSystemTray: false, + multiArch: false, targets: 'deb', iterCopyFile: false, systemTrayIcon: '', diff --git a/bin/types.ts b/bin/types.ts index dbb9672..02955f9 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -35,6 +35,9 @@ export interface PakeCliOptions { // /** 递归拷贝,当url为本地文件路径时候,若开启该选项,则将url路径文件所在文件夹以及所有子文件都拷贝到pake静态文件夹,默认不开启 */ iterCopyFile: false; + /** mutli arch, Supports both Intel and m1 chips, only for Mac */ + multiArch: boolean; + // 包输出产物,对linux用户有效,默认为deb,可选appimage, 或者all(即同时输出deb和all); targets: string;