feat(cli): add --use-cross command for building with cross (#1584)

closes #1582
This commit is contained in:
Boshen 2023-05-09 09:30:30 +08:00 committed by GitHub
parent 31ce5eb823
commit 58600883dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View file

@ -227,6 +227,12 @@ const BUILD_OPTIONS: CommandSchema = {
'[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform', '[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
short: 'x', short: 'x',
}, },
{
name: 'useCross',
type: 'boolean',
description:
'[experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`',
},
{ {
name: 'watch', name: 'watch',
type: 'boolean', type: 'boolean',

View file

@ -44,6 +44,7 @@ new NapiCli().build({
| bin | --bin | string | false | | Build only the specified binary | | bin | --bin | string | false | | Build only the specified binary |
| package | --package,-p | string | false | | Build the specified library or the one at cwd | | package | --package,-p | string | false | | Build the specified library or the one at cwd |
| crossCompile | --cross-compile,-x | boolean | false | | [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform | | crossCompile | --cross-compile,-x | boolean | false | | [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform |
| useCross | --use-cross | boolean | false | | [experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo` |
| watch | --watch,-w | boolean | false | | watch the crate changes and build continiously with `cargo-watch` crates | | watch | --watch,-w | boolean | false | | watch the crate changes and build continiously with `cargo-watch` crates |
| features | --features,-F | string[] | false | | Space-separated list of features to activate | | features | --features,-F | string[] | false | | Space-separated list of features to activate |
| allFeatures | --all-features | boolean | false | | Activate all available features | | allFeatures | --all-features | boolean | false | | Activate all available features |

View file

@ -150,7 +150,8 @@ class Builder {
const controller = new AbortController() const controller = new AbortController()
const buildTask = new Promise<void>((resolve, reject) => { const buildTask = new Promise<void>((resolve, reject) => {
const buildProcess = spawn('cargo', this.args, { const command = this.options.useCross ? 'cross' : 'cargo'
const buildProcess = spawn(command, this.args, {
env: { env: {
...process.env, ...process.env,
...this.envs, ...this.envs,

View file

@ -97,6 +97,11 @@ export abstract class BaseBuildCommand extends Command {
'[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform', '[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
}) })
useCross?: boolean = Option.Boolean('--use-cross', {
description:
'[experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`',
})
watch?: boolean = Option.Boolean('--watch,-w', { watch?: boolean = Option.Boolean('--watch,-w', {
description: description:
'watch the crate changes and build continiously with `cargo-watch` crates', 'watch the crate changes and build continiously with `cargo-watch` crates',
@ -135,6 +140,7 @@ export abstract class BaseBuildCommand extends Command {
bin: this.bin, bin: this.bin,
package: this.package, package: this.package,
crossCompile: this.crossCompile, crossCompile: this.crossCompile,
useCross: this.useCross,
watch: this.watch, watch: this.watch,
features: this.features, features: this.features,
allFeatures: this.allFeatures, allFeatures: this.allFeatures,
@ -223,6 +229,10 @@ export interface BuildOptions {
* [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform * [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform
*/ */
crossCompile?: boolean crossCompile?: boolean
/**
* [experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`
*/
useCross?: boolean
/** /**
* watch the crate changes and build continiously with `cargo-watch` crates * watch the crate changes and build continiously with `cargo-watch` crates
*/ */