feat(cli): support default cross-compilation targets from npmextra.json
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-02-09 - 1.2.0 - feat(cli)
|
||||||
|
support default cross-compilation targets from npmextra.json
|
||||||
|
|
||||||
|
- Add @push.rocks/npmextra dependency and export plugin in ts/plugins.ts
|
||||||
|
- Introduce ITsrustConfig and read configuration via plugins.npmextra.Npmextra in TsRustCli
|
||||||
|
- Use npmextra.json targets as fallback when no CLI --target flags are provided
|
||||||
|
- Update README to document npmextra.json configuration for default targets
|
||||||
|
|
||||||
## 2026-02-09 - 1.1.0 - feat(cross-compile)
|
## 2026-02-09 - 1.1.0 - feat(cross-compile)
|
||||||
add cross-compilation support with --target flag, friendly target aliases, and automatic rustup target installation
|
add cross-compilation support with --target flag, friendly target aliases, and automatic rustup target installation
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"homepage": "https://code.foss.global/git.zone/tsrust#README",
|
"homepage": "https://code.foss.global/git.zone/tsrust#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/early": "^4.0.4",
|
"@push.rocks/early": "^4.0.4",
|
||||||
|
"@push.rocks/npmextra": "^5.3.3",
|
||||||
"@push.rocks/smartcli": "^4.0.19",
|
"@push.rocks/smartcli": "^4.0.19",
|
||||||
"@push.rocks/smartfile": "^13.1.2",
|
"@push.rocks/smartfile": "^13.1.2",
|
||||||
"@push.rocks/smartpath": "^6.0.0",
|
"@push.rocks/smartpath": "^6.0.0",
|
||||||
|
|||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -11,6 +11,9 @@ importers:
|
|||||||
'@push.rocks/early':
|
'@push.rocks/early':
|
||||||
specifier: ^4.0.4
|
specifier: ^4.0.4
|
||||||
version: 4.0.4
|
version: 4.0.4
|
||||||
|
'@push.rocks/npmextra':
|
||||||
|
specifier: ^5.3.3
|
||||||
|
version: 5.3.3
|
||||||
'@push.rocks/smartcli':
|
'@push.rocks/smartcli':
|
||||||
specifier: ^4.0.19
|
specifier: ^4.0.19
|
||||||
version: 4.0.20
|
version: 4.0.20
|
||||||
|
|||||||
14
readme.md
14
readme.md
@@ -119,6 +119,20 @@ dist_rust/
|
|||||||
|
|
||||||
`tsrust` automatically installs missing rustup targets via `rustup target add` when needed.
|
`tsrust` automatically installs missing rustup targets via `rustup target add` when needed.
|
||||||
|
|
||||||
|
### Configuration via npmextra.json
|
||||||
|
|
||||||
|
You can set default cross-compilation targets in your project's `npmextra.json` file so you don't need to pass `--target` flags every time:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@git.zone/tsrust": {
|
||||||
|
"targets": ["linux_arm64", "linux_amd64"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When targets are configured in `npmextra.json`, simply running `tsrust` will cross-compile for all listed targets. CLI `--target` flags take full precedence — if any `--target` is provided, the `npmextra.json` targets are ignored entirely.
|
||||||
|
|
||||||
### 🗑️ Clean Only
|
### 🗑️ Clean Only
|
||||||
|
|
||||||
Remove all build artifacts without rebuilding:
|
Remove all build artifacts without rebuilding:
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@git.zone/tsrust',
|
name: '@git.zone/tsrust',
|
||||||
version: '1.1.0',
|
version: '1.2.0',
|
||||||
description: 'A tool for compiling Rust projects, detecting Cargo workspaces, building with cargo, and placing binaries in a conventional dist_rust directory.'
|
description: 'A tool for compiling Rust projects, detecting Cargo workspaces, building with cargo, and placing binaries in a conventional dist_rust directory.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,20 @@ function friendlyName(triple: string): string {
|
|||||||
return triple.replace(/-/g, '_');
|
return triple.replace(/-/g, '_');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ITsrustConfig {
|
||||||
|
targets?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export class TsRustCli {
|
export class TsRustCli {
|
||||||
private cli: plugins.smartcli.Smartcli;
|
private cli: plugins.smartcli.Smartcli;
|
||||||
private cwd: string;
|
private cwd: string;
|
||||||
|
private config: ITsrustConfig;
|
||||||
|
|
||||||
constructor(cwd: string = process.cwd()) {
|
constructor(cwd: string = process.cwd()) {
|
||||||
this.cwd = cwd;
|
this.cwd = cwd;
|
||||||
this.cli = new plugins.smartcli.Smartcli();
|
this.cli = new plugins.smartcli.Smartcli();
|
||||||
|
const npmextraInstance = new plugins.npmextra.Npmextra(this.cwd);
|
||||||
|
this.config = npmextraInstance.dataFor<ITsrustConfig>('@git.zone/tsrust', { targets: [] });
|
||||||
this.registerCommands();
|
this.registerCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,11 +106,11 @@ export class TsRustCli {
|
|||||||
const distDir = path.join(this.cwd, 'dist_rust');
|
const distDir = path.join(this.cwd, 'dist_rust');
|
||||||
const profile = isDebug ? 'debug' : 'release';
|
const profile = isDebug ? 'debug' : 'release';
|
||||||
|
|
||||||
// Parse --target flag (can appear multiple times)
|
// Parse --target flag (can appear multiple times), fall back to npmextra.json config
|
||||||
const rawTargets = (argvArg as any).target;
|
const cliTargets = (argvArg as any).target;
|
||||||
const targets: string[] = rawTargets
|
const targets: string[] = cliTargets
|
||||||
? Array.isArray(rawTargets) ? rawTargets : [rawTargets]
|
? (Array.isArray(cliTargets) ? cliTargets : [cliTargets])
|
||||||
: [];
|
: this.config.targets || [];
|
||||||
|
|
||||||
if (targets.length > 0) {
|
if (targets.length > 0) {
|
||||||
// Cross-compilation mode
|
// Cross-compilation mode
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as early from '@push.rocks/early';
|
import * as early from '@push.rocks/early';
|
||||||
|
import * as npmextra from '@push.rocks/npmextra';
|
||||||
import * as smartcli from '@push.rocks/smartcli';
|
import * as smartcli from '@push.rocks/smartcli';
|
||||||
import * as smartfile from '@push.rocks/smartfile';
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as smartpath from '@push.rocks/smartpath';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
@@ -6,6 +7,7 @@ import * as smartshell from '@push.rocks/smartshell';
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
early,
|
early,
|
||||||
|
npmextra,
|
||||||
smartcli,
|
smartcli,
|
||||||
smartfile,
|
smartfile,
|
||||||
smartpath,
|
smartpath,
|
||||||
|
|||||||
Reference in New Issue
Block a user