@tishlang/tish-format 3.10.11 → 3.11.0

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.
package/bin/tish-format CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "tishlang_fmt"
3
- version = "3.10.11"
3
+ version = "3.11.0"
4
4
  edition = "2021"
5
5
  description = "Opinionated formatter for Tish source (parse → pretty-print)"
6
6
  license-file = { workspace = true }
@@ -287,7 +287,9 @@ edition = "2021"
287
287
  .parent()
288
288
  .and_then(|p| p.parent())
289
289
  .map(|ws| ws.join("target"));
290
- let target_dir = workspace_target.filter(|p| p.exists());
290
+ let target_dir = workspace_target
291
+ .filter(|p| p.exists())
292
+ .or_else(shared_native_target_dir);
291
293
  let cross = build_config.cargo_target.as_deref();
292
294
  let release_sub = if let Some(triple) = cross {
293
295
  format!("{triple}/release")
@@ -456,7 +458,10 @@ fn runtime_dep_toml(runtime_path: &str, features_str: &str) -> String {
456
458
  if let Some(v) = released_compiler_version() {
457
459
  format!("tishlang_runtime = {{ version = {:?}{} }}", v, features_str)
458
460
  } else {
459
- format!("tishlang_runtime = {{ path = {:?}{} }}", runtime_path, features_str)
461
+ format!(
462
+ "tishlang_runtime = {{ path = {:?}{} }}",
463
+ runtime_path, features_str
464
+ )
460
465
  }
461
466
  }
462
467
 
@@ -693,8 +698,7 @@ tishlang_runtime = {{ path = {runtime:?}{version}{features} }}
693
698
  fs::write(src_dir.join("generated_native.rs"), gen)
694
699
  .map_err(|e| format!("Cannot write generated_native.rs: {}", e))?;
695
700
  }
696
- fs::write(src_dir.join("lib.rs"), lib_rs)
697
- .map_err(|e| format!("Cannot write lib.rs: {}", e))?;
701
+ fs::write(src_dir.join("lib.rs"), lib_rs).map_err(|e| format!("Cannot write lib.rs: {}", e))?;
698
702
 
699
703
  println!("Emitted Rust library crate: {}", output_path.display());
700
704
  Ok(())
@@ -739,8 +743,7 @@ fn build_gba_rom(
739
743
  // the source of truth. The generated ROM crate must depend on the SAME agb: a skew would pull in
740
744
  // two agb crates and mismatch types at the sprite-registration boundary. Falls back to a known
741
745
  // pin only if the line can't be read (never blocks the build on a parse miss).
742
- let agb_version =
743
- read_facade_agb_version(&facade_path).unwrap_or_else(|| "0.25.0".to_string());
746
+ let agb_version = read_facade_agb_version(&facade_path).unwrap_or_else(|| "0.25.0".to_string());
744
747
 
745
748
  let out_stem = output_path
746
749
  .file_stem()
@@ -816,11 +819,13 @@ agb = "{agb_version}"
816
819
  // Only the channel is inherited. `components` stays `rust-src` because that is what build-std
817
820
  // needs — copying a project's `clippy`/`rustfmt` entries in would fail the ROM build whenever
818
821
  // the pinned toolchain lacks a component the ROM never uses.
819
- let channel =
820
- find_project_toolchain_channel(&base).unwrap_or_else(|| "nightly".to_string());
822
+ let channel = find_project_toolchain_channel(&base).unwrap_or_else(|| "nightly".to_string());
821
823
  fs::write(
822
824
  build_dir.join("rust-toolchain.toml"),
823
- format!("[toolchain]\nchannel = \"{}\"\ncomponents = [\"rust-src\"]\n", channel),
825
+ format!(
826
+ "[toolchain]\nchannel = \"{}\"\ncomponents = [\"rust-src\"]\n",
827
+ channel
828
+ ),
824
829
  )
825
830
  .map_err(|e| format!("Cannot write rust-toolchain.toml: {}", e))?;
826
831
 
@@ -971,6 +976,30 @@ fn find_project_toolchain_channel(start: &Path) -> Option<String> {
971
976
  None
972
977
  }
973
978
 
979
+ /// `TISH_NATIVE_TARGET_DIR` — opt-in shared cargo target dir for native (desktop) builds.
980
+ ///
981
+ /// Native builds compile the generated crate under a per-process temp dir that is deleted on
982
+ /// success (`cleanup_build_dir`), so nothing survives between two `tish build --target native`
983
+ /// invocations and CI recompiles every dependency each run. Inside the tish workspace the
984
+ /// workspace `target/` is shared automatically; a released compiler has no workspace, and this
985
+ /// env var is the equivalent for it: point it at a directory that persists (a CI cache) and
986
+ /// cargo reuses the dependency artifacts across builds. Deliberately NOT the ambient
987
+ /// `CARGO_TARGET_DIR` — see the GBA path for why that is scrubbed (`TISH_GBA_TARGET_DIR` is the
988
+ /// same opt-in for ROM builds). The directory is created if missing.
989
+ fn shared_native_target_dir() -> Option<PathBuf> {
990
+ let dir = std::env::var_os("TISH_NATIVE_TARGET_DIR")
991
+ .map(PathBuf::from)
992
+ .filter(|p| !p.as_os_str().is_empty())?;
993
+ if let Err(e) = fs::create_dir_all(&dir) {
994
+ eprintln!(
995
+ "warning: TISH_NATIVE_TARGET_DIR={} is not usable ({e}); building in the temp dir",
996
+ dir.display()
997
+ );
998
+ return None;
999
+ }
1000
+ Some(dir)
1001
+ }
1002
+
974
1003
  /// Remove a finished build's per-PID source directory (#384). Called only on SUCCESS, after the
975
1004
  /// binary is copied out — the dir is then disposable (it holds only the generated crate source;
976
1005
  /// compiled artifacts live in the shared workspace `target/`). Left in place on any earlier error so a
@@ -1126,7 +1155,9 @@ edition = "2021"
1126
1155
  .parent()
1127
1156
  .and_then(|p| p.parent())
1128
1157
  .map(|ws| ws.join("target"));
1129
- let target_dir = workspace_target.filter(|p| p.exists());
1158
+ let target_dir = workspace_target
1159
+ .filter(|p| p.exists())
1160
+ .or_else(shared_native_target_dir);
1130
1161
  let binary_dir = target_dir
1131
1162
  .as_ref()
1132
1163
  .map(|t| t.join("release"))
@@ -1188,14 +1219,41 @@ mod tests {
1188
1219
  let _ = fs::remove_dir_all(&base);
1189
1220
  }
1190
1221
 
1222
+ /// `TISH_NATIVE_TARGET_DIR`: unset/empty → None (temp-dir build); set → that dir, created.
1223
+ #[test]
1224
+ fn shared_native_target_dir_follows_env() {
1225
+ use super::shared_native_target_dir;
1226
+ use std::fs;
1227
+ use std::path::PathBuf;
1228
+ // Only this test touches TISH_NATIVE_TARGET_DIR; the lock keeps it single-threaded anyway.
1229
+ use std::sync::Mutex;
1230
+ static ENV_LOCK: Mutex<()> = Mutex::new(());
1231
+ let _guard = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
1232
+ std::env::remove_var("TISH_NATIVE_TARGET_DIR");
1233
+ assert!(shared_native_target_dir().is_none());
1234
+ std::env::set_var("TISH_NATIVE_TARGET_DIR", "");
1235
+ assert!(shared_native_target_dir().is_none());
1236
+ // Scratch under the workspace target/ (never /tmp), unique per case.
1237
+ let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
1238
+ .join("../../target/tmp_shared_target_test")
1239
+ .join(format!("t_{}", std::process::id()));
1240
+ let _ = fs::remove_dir_all(&dir);
1241
+ std::env::set_var("TISH_NATIVE_TARGET_DIR", &dir);
1242
+ let got = shared_native_target_dir().expect("set → Some");
1243
+ assert_eq!(got, dir);
1244
+ assert!(dir.is_dir(), "the shared target dir is created on demand");
1245
+ std::env::remove_var("TISH_NATIVE_TARGET_DIR");
1246
+ let _ = fs::remove_dir_all(dir.parent().unwrap());
1247
+ }
1248
+
1191
1249
  /// #384: `cleanup_build_dir` removes a finished build's dir by default, and preserves it under
1192
1250
  /// `TISH_KEEP_BUILD_DIR=1`.
1193
1251
  #[test]
1194
1252
  fn cleanup_build_dir_removes_by_default_and_keeps_on_flag() {
1195
1253
  use std::path::PathBuf;
1196
1254
  // Scratch under the workspace target/ (never /tmp), unique per case.
1197
- let base: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
1198
- .join("../../target/tmp_cleanup_test");
1255
+ let base: PathBuf =
1256
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/tmp_cleanup_test");
1199
1257
  let removed = base.join("to_remove");
1200
1258
  let kept = base.join("to_keep");
1201
1259
  for d in [&removed, &kept] {
@@ -1209,7 +1267,10 @@ mod tests {
1209
1267
 
1210
1268
  std::env::set_var("TISH_KEEP_BUILD_DIR", "1");
1211
1269
  super::cleanup_build_dir(&kept);
1212
- assert!(kept.exists(), "TISH_KEEP_BUILD_DIR=1 should preserve the build dir");
1270
+ assert!(
1271
+ kept.exists(),
1272
+ "TISH_KEEP_BUILD_DIR=1 should preserve the build dir"
1273
+ );
1213
1274
  std::env::remove_var("TISH_KEEP_BUILD_DIR");
1214
1275
 
1215
1276
  let _ = std::fs::remove_dir_all(&base);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tishlang/tish-format",
3
- "version": "3.10.11",
3
+ "version": "3.11.0",
4
4
  "description": "Tish code formatter",
5
5
  "license": "PIF",
6
6
  "repository": {
Binary file
Binary file
Binary file
Binary file
Binary file