@git.zone/tsrust 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/index.d.ts +2 -0
  3. package/dist_ts/index.js +3 -1
  4. package/dist_ts/mod_artifact/classes.artifactassembler.d.ts +48 -0
  5. package/dist_ts/mod_artifact/classes.artifactassembler.js +842 -0
  6. package/dist_ts/mod_artifact/index.d.ts +1 -0
  7. package/dist_ts/mod_artifact/index.js +2 -0
  8. package/dist_ts/mod_cli/classes.tsrustcli.d.ts +5 -2
  9. package/dist_ts/mod_cli/classes.tsrustcli.js +122 -75
  10. package/dist_ts/mod_cli/helpers.codesign.d.ts +2 -0
  11. package/dist_ts/mod_cli/helpers.codesign.js +48 -0
  12. package/dist_ts/mod_cli/helpers.targets.d.ts +20 -0
  13. package/dist_ts/mod_cli/helpers.targets.js +106 -0
  14. package/dist_ts/mod_cli/index.d.ts +1 -0
  15. package/dist_ts/mod_cli/index.js +2 -1
  16. package/dist_ts/mod_elf/classes.provenance.d.ts +2 -1
  17. package/dist_ts/mod_elf/classes.provenance.js +0 -0
  18. package/dist_ts/mod_provenance/classes.gitstate.d.ts +7 -0
  19. package/dist_ts/mod_provenance/classes.gitstate.js +34 -0
  20. package/dist_ts/mod_provenance/classes.provenancestore.d.ts +11 -0
  21. package/dist_ts/mod_provenance/classes.provenancestore.js +184 -0
  22. package/dist_ts/mod_provenance/helpers.owneridentity.d.ts +2 -0
  23. package/dist_ts/mod_provenance/helpers.owneridentity.js +57 -0
  24. package/dist_ts/mod_provenance/index.d.ts +3 -0
  25. package/dist_ts/mod_provenance/index.js +4 -0
  26. package/package.json +3 -3
  27. package/readme.hints.md +6 -3
  28. package/readme.md +77 -5
  29. package/ts/00_commitinfo_data.ts +1 -1
  30. package/ts/index.ts +2 -0
  31. package/ts/mod_artifact/classes.artifactassembler.ts +1028 -0
  32. package/ts/mod_artifact/index.ts +6 -0
  33. package/ts/mod_cli/classes.tsrustcli.ts +179 -95
  34. package/ts/mod_cli/helpers.codesign.ts +71 -0
  35. package/ts/mod_cli/helpers.targets.ts +141 -0
  36. package/ts/mod_cli/index.ts +10 -0
  37. package/ts/mod_elf/classes.provenance.ts +0 -0
  38. package/ts/mod_provenance/classes.gitstate.ts +49 -0
  39. package/ts/mod_provenance/classes.provenancestore.ts +194 -0
  40. package/ts/mod_provenance/helpers.owneridentity.ts +57 -0
  41. package/ts/mod_provenance/index.ts +10 -0
package/readme.md CHANGED
@@ -50,7 +50,8 @@ This will:
50
50
  4. Run `cargo build --release` with full streaming output
51
51
  5. Store Cargo intermediates in `.nogit/tsrust-target` by default
52
52
  6. Copy each binary to `dist_rust/` with executable permissions (`chmod 755`)
53
- 7. Report file sizes and total build time
53
+ 7. Write a SHA-256-bound provenance sidecar without changing the binary bytes
54
+ 8. Report file sizes and total build time
54
55
 
55
56
  **Example output:**
56
57
 
@@ -63,6 +64,7 @@ Running: CARGO_TARGET_DIR="/path/to/project/.nogit/tsrust-target" cargo build --
63
64
  Compiling rustproxy v0.1.0
64
65
  Finished `release` profile [optimized] target(s) in 29.01s
65
66
  Copied rustproxy (13.4 MB) -> dist_rust/rustproxy
67
+ Wrote provenance: @example/rustproxy@1.0.0 abc123def456 (native)
66
68
  Done in 29.2s
67
69
  ```
68
70
 
@@ -127,7 +129,9 @@ When using `--target`, output binaries are named `<binname>_<os>_<arch>`:
127
129
  ```
128
130
  dist_rust/
129
131
  ├── rustproxy_linux_arm64
130
- └── rustproxy_linux_amd64
132
+ ├── rustproxy_linux_arm64.tsrust-build.json
133
+ ├── rustproxy_linux_amd64
134
+ └── rustproxy_linux_amd64.tsrust-build.json
131
135
  ```
132
136
 
133
137
  `tsrust` automatically installs missing rustup targets via `rustup target add` when needed.
@@ -147,12 +151,56 @@ You can set default cross-compilation targets in your project's `.smartconfig.js
147
151
  }
148
152
  ```
149
153
 
150
- When targets are configured in `.smartconfig.json`, simply running `tsrust` will cross-compile for all listed targets. CLI `--target` flags take full precedence — if any `--target` is provided, the `.smartconfig.json` targets are ignored entirely.
154
+ When targets are configured in `.smartconfig.json`, simply running `tsrust` will cross-compile for all listed targets. CLI `--target` flags determine the selected targets when provided. The complete configuration is still validated first, so malformed legacy or host-specific entries are always rejected.
155
+
156
+ For builds split across Linux and macOS hosts, select targets by build host:
157
+
158
+ ```json
159
+ {
160
+ "@git.zone/tsrust": {
161
+ "targetsByHost": {
162
+ "linux": ["linux_amd64", "linux_arm64"],
163
+ "macos": ["macos_amd64", "macos_arm64"]
164
+ },
165
+ "locked": true
166
+ }
167
+ }
168
+ ```
169
+
170
+ Host selection uses this precedence: CLI `--target`, exact host key, OS-family key, legacy `targets`, then a native build. Exact host keys are `linux_amd64`, `linux_arm64`, `macos_amd64`, and `macos_arm64`; OS-family keys are `linux` and `macos`. The selected entries are not merged, so an exact host entry completely replaces its family entry for that host.
151
171
 
152
172
  `locked: true` runs Cargo builds with `--locked` for deterministic dependency resolution. This requires `Cargo.lock` to exist and remain consistent with the manifests; Cargo fails instead of updating an inconsistent lockfile.
153
173
 
154
174
  `targetDir` is optional. It must point to a tsrust-owned path under `.nogit/`, such as `.nogit/tsrust-target` or `.nogit/tsrust-custom-target`. You can also set `TSRUST_TARGET_DIR` for one-off runs. `pruneAfterBuild: true` or `TSRUST_PRUNE_AFTER_BUILD=true` removes the marked managed target cache after binaries have been copied to `dist_rust/`.
155
175
 
176
+ ### Build Provenance
177
+
178
+ Every new build writes `<binary>.tsrust-build.json` beside the binary. In a Git checkout, the sidecar records the consuming package name and version, exact commit and dirty state, target, build time, and tsrust version. Non-Git builds record `gitCommit: "unknown"` and omit `gitDirty`. The sidecar also contains the binary's SHA-256 digest, so provenance reads fail if either file no longer belongs to the pair. The binary itself remains byte-identical to the postprocessed Cargo target-cache binary, preserving Mach-O signatures and other binary-format integrity checks. On Darwin targets, tsrust preserves an existing valid signature and applies an ad-hoc signature only when `codesign` explicitly identifies the Cargo output as unsigned. Invalid or ambiguous signature states fail the build. Signing happens before the binary is copied and before its provenance digest is written.
179
+
180
+ Inspect a built artifact with:
181
+
182
+ ```bash
183
+ tsrust inspect dist_rust/rustproxy_linux_amd64
184
+ ```
185
+
186
+ `inspect` verifies and reads the sidecar. It retains read compatibility with provenance trailers produced by tsrust 1.7 and 1.8, but new builds no longer append those trailers.
187
+
188
+ tsrust snapshots the Git commit and complete worktree status before each Cargo build and verifies that neither changed before copying artifacts. Dirty builds remain possible for development and are marked as dirty; strict multi-host assembly rejects them.
189
+
190
+ ### Multi-Host Assembly
191
+
192
+ Each host build owns and cleans its own `dist_rust/`. Copy those host outputs into separate artifact directories, then assemble the complete matrix from the same clean Git checkout and package version:
193
+
194
+ ```bash
195
+ tsrust assemble .nogit/artifacts/linux .nogit/artifacts/macos
196
+ ```
197
+
198
+ The union of `targets` and `targetsByHost` defines the required target matrix. Repeated `--target` options can define an explicit matrix instead. Assembly always publishes to the tsrust-owned `dist_rust/` directory.
199
+
200
+ Assembly requires every Cargo binary for every expected target. It rejects missing, duplicate, unexpected, non-executable, symlinked, hash-mismatched, dirty, wrong-commit, wrong-package, and wrong-tsrust-version inputs. Validation and copying happen in a same-filesystem transaction under `.nogit/tsrust-assembly/`, guarded by the atomically published `.nogit/tsrust-assembly.lock`. The Git commit, clean worktree, and package identity are checked again immediately before publication. The previous output is retained until the complete staged matrix is ready, and successful publication removes files left by older matrices.
201
+
202
+ The transaction records a boot-scoped host identity, process, owner token, and publication phase. A separate atomic recovery claim serializes dead-owner recovery. When the owner lock and state are readable and consistent, a later invocation on the owning host rejects a live process, rolls back an interrupted pre-commit publication after that process exits, and completes publication or cleanup after durable commit intent. A confirmed missing state file is safe to clean because the owner-lock protocol forbids output mutation before initial state persistence; malformed, non-regular, unreadable, or owner-inconsistent state fails closed. A transaction owned by another host is never taken over automatically because portable filesystem operations cannot fence a paused remote writer. If committed cleanup cannot finish immediately, the programmatic result reports `cleanupPending: true` and the CLI prints a warning; the owning process can retry it immediately.
203
+
156
204
  ### Static Linking
157
205
 
158
206
  `tsrust` can produce fully statically linked Linux binaries (static-pie) that run on both glibc distros (Debian/Ubuntu) and musl distros (Alpine). Enable it via `.smartconfig.json`:
@@ -260,7 +308,8 @@ my-project/
260
308
  │ ├── Cargo.toml
261
309
  │ └── src/
262
310
  ├── dist_rust/ # 📦 Output: compiled binaries go here
263
- │ └── my-binary
311
+ │ ├── my-binary
312
+ │ └── my-binary.tsrust-build.json
264
313
  ├── .nogit/
265
314
  │ └── tsrust-target/ # 🧹 Managed Cargo target cache
266
315
  ├── ts/ # (your TypeScript code, built by tsbuild)
@@ -286,7 +335,18 @@ If no `rust/` directory is found, `tsrust` checks for `ts_rust/` as a fallback.
286
335
  `tsrust` exports its internals for use in other Node.js/TypeScript tools:
287
336
 
288
337
  ```typescript
289
- import { CargoConfig, CargoRunner, FsHelpers, TsRustCli, resolveManagedTargetDir } from '@git.zone/tsrust';
338
+ import {
339
+ ArtifactAssembler,
340
+ CargoConfig,
341
+ CargoRunner,
342
+ FsHelpers,
343
+ ProvenanceStore,
344
+ TsRustCli,
345
+ configuredAssemblyTargets,
346
+ normalizeTargets,
347
+ resolveBuildTargets,
348
+ resolveManagedTargetDir,
349
+ } from '@git.zone/tsrust';
290
350
 
291
351
  // Parse a Cargo workspace
292
352
  const config = new CargoConfig('/path/to/rust');
@@ -309,6 +369,18 @@ const size = await FsHelpers.getFileSize(dest);
309
369
  console.log(FsHelpers.formatFileSize(size)); // "13.4 MB"
310
370
  ```
311
371
 
372
+ Important exported build and artifact APIs:
373
+
374
+ | API | Purpose |
375
+ | --- | --- |
376
+ | `resolveBuildTargets()` | Apply CLI, exact-host, OS-family, legacy, and native target precedence. |
377
+ | `configuredAssemblyTargets()` | Normalize and deduplicate the union required for multi-host assembly. |
378
+ | `normalizeTargets()` | Resolve friendly aliases and reject invalid or colliding target names. |
379
+ | `ProvenanceStore` | Write, hash-verify, and read byte-preserving provenance sidecars. |
380
+ | `ArtifactAssembler` | Validate and transactionally publish a complete exact-commit artifact matrix to `dist_rust/`. |
381
+ | `captureGitSnapshot()` / `assertGitSnapshotUnchanged()` | Capture and compare Git commit and worktree state around a build. |
382
+ | `ProvenanceStamper` | Read legacy tsrust 1.7/1.8 embedded trailers; new builds use `ProvenanceStore`. |
383
+
312
384
  ## License and Legal Information
313
385
 
314
386
  This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license.md) file.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@git.zone/tsrust',
6
- version: '1.8.0',
6
+ version: '1.9.1',
7
7
  description: 'A tool for compiling Rust projects, detecting Cargo workspaces, building with cargo, and placing binaries in a conventional dist_rust directory.'
8
8
  }
package/ts/index.ts CHANGED
@@ -3,8 +3,10 @@ plugins.early.start('@git.zone/tsrust');
3
3
 
4
4
  export * from './mod_fs/index.js';
5
5
  export * from './mod_cargo/index.js';
6
+ export * from './mod_artifact/index.js';
6
7
  export * from './mod_cli/index.js';
7
8
  export * from './mod_elf/index.js';
9
+ export * from './mod_provenance/index.js';
8
10
  export * from './mod_toolchain/index.js';
9
11
 
10
12
  plugins.early.stop();