refactor(cli): --profile flag (#1604)
This commit is contained in:
parent
82c2113c24
commit
c7d6ee6e4b
7 changed files with 31 additions and 12 deletions
6
.github/workflows/cli-binary.yml
vendored
6
.github/workflows/cli-binary.yml
vendored
|
@ -47,10 +47,6 @@ jobs:
|
|||
run: |
|
||||
yarn workspace binary build
|
||||
./examples/binary/napi-examples-binary
|
||||
yarn workspace binary build --profile napi-rs-custom
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
cargo install cargo-cache --no-default-features --features ci-autoclean
|
||||
cargo-cache
|
||||
|
|
3
.github/workflows/test.yaml
vendored
3
.github/workflows/test.yaml
vendored
|
@ -73,3 +73,6 @@ jobs:
|
|||
run: |
|
||||
node ./node_modules/electron/install.js
|
||||
xvfb-run --auto-servernum yarn test:electron
|
||||
|
||||
- name: Test build with profile
|
||||
run: yarn workspace @examples/napi build --profile napi-rs-custom
|
||||
|
|
|
@ -18,3 +18,7 @@ exclude = ["./testing"]
|
|||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
[profile.napi-rs-custom]
|
||||
inherits = "dev"
|
||||
codegen-units = 1024
|
||||
|
|
|
@ -220,6 +220,11 @@ const BUILD_OPTIONS: CommandSchema = {
|
|||
description: 'Build the specified library or the one at cwd',
|
||||
short: 'p',
|
||||
},
|
||||
{
|
||||
name: 'profile',
|
||||
type: 'string',
|
||||
description: 'Build artifacts with the specified profile',
|
||||
},
|
||||
{
|
||||
name: 'crossCompile',
|
||||
type: 'boolean',
|
||||
|
|
|
@ -43,6 +43,7 @@ new NapiCli().build({
|
|||
| verbose | --verbose,-v | boolean | false | | Verbosely log build command trace |
|
||||
| bin | --bin | string | false | | Build only the specified binary |
|
||||
| package | --package,-p | string | false | | Build the specified library or the one at cwd |
|
||||
| profile | --profile | string | false | | Build artifacts with the specified profile |
|
||||
| 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 |
|
||||
|
|
|
@ -402,6 +402,10 @@ class Builder {
|
|||
this.args.push('--target-dir', this.options.targetDir)
|
||||
}
|
||||
|
||||
if (this.options.profile) {
|
||||
this.args.push('--profile', this.options.profile)
|
||||
}
|
||||
|
||||
if (this.options.cargoOptions?.length) {
|
||||
this.args.push(...this.options.cargoOptions)
|
||||
}
|
||||
|
@ -460,13 +464,10 @@ class Builder {
|
|||
return
|
||||
}
|
||||
|
||||
let outputFolder = this.options.release ? 'release' : 'debug'
|
||||
if (this.options.cargoOptions?.includes('--profile')) {
|
||||
const args = this.options.cargoOptions
|
||||
const profileIndex = args.indexOf('--profile')
|
||||
outputFolder = args[profileIndex + 1]
|
||||
}
|
||||
const src = join(this.targetDir, this.target.triple, outputFolder, srcName)
|
||||
const profile =
|
||||
this.options.profile ?? (this.options.release ? 'release' : 'debug')
|
||||
const src = join(this.targetDir, this.target.triple, profile, srcName)
|
||||
debug(`Copy artifact from: [${src}]`)
|
||||
const dest = join(this.outputDir, destName)
|
||||
|
||||
try {
|
||||
|
|
|
@ -92,6 +92,10 @@ export abstract class BaseBuildCommand extends Command {
|
|||
description: 'Build the specified library or the one at cwd',
|
||||
})
|
||||
|
||||
profile?: string = Option.String('--profile', {
|
||||
description: 'Build artifacts with the specified profile',
|
||||
})
|
||||
|
||||
crossCompile?: boolean = Option.Boolean('--cross-compile,-x', {
|
||||
description:
|
||||
'[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
|
||||
|
@ -139,6 +143,7 @@ export abstract class BaseBuildCommand extends Command {
|
|||
verbose: this.verbose,
|
||||
bin: this.bin,
|
||||
package: this.package,
|
||||
profile: this.profile,
|
||||
crossCompile: this.crossCompile,
|
||||
useCross: this.useCross,
|
||||
watch: this.watch,
|
||||
|
@ -225,6 +230,10 @@ export interface BuildOptions {
|
|||
* Build the specified library or the one at cwd
|
||||
*/
|
||||
package?: string
|
||||
/**
|
||||
* Build artifacts with the specified profile
|
||||
*/
|
||||
profile?: string
|
||||
/**
|
||||
* [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue