@dbx-tools/projen 0.6.193 → 0.6.194

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/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  // Hand edits are overwritten on the next watch; this file is read-only.
4
4
 
5
5
  export const PACKAGE_IDENTIFIER = "@dbx-tools/projen";
6
- export const PACKAGE_VERSION = "0.6.192";
6
+ export const PACKAGE_VERSION = "0.6.193";
7
7
  export * as barrels from "./src/barrels.ts";
8
8
  export * as bunApp from "./src/bun-app.ts";
9
9
  export * as bunWorkflow from "./src/bun-workflow.ts";
package/package.json CHANGED
@@ -25,9 +25,9 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@clack/prompts": "^1.7.0",
28
- "@dbx-tools/core": "0.6.193",
29
- "@dbx-tools/path": "0.6.193",
30
- "@dbx-tools/shared-core": "0.6.193",
28
+ "@dbx-tools/core": "0.6.194",
29
+ "@dbx-tools/path": "0.6.194",
30
+ "@dbx-tools/shared-core": "0.6.194",
31
31
  "commander": "^15.0.0",
32
32
  "concurrently": "^10.0.3",
33
33
  "constructs": "^10.6.0",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "main": "index.ts",
49
49
  "license": "Apache-2.0",
50
- "version": "0.6.193",
50
+ "version": "0.6.194",
51
51
  "types": "index.ts",
52
52
  "type": "module",
53
53
  "exports": {
package/src/project-rs.ts CHANGED
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
5
5
  import { project as coreProject } from "@dbx-tools/core";
6
6
  import { string } from "@dbx-tools/shared-core";
7
7
  import { Project, TextFile, javascript } from "projen";
8
+ import { GithubWorkflow } from "projen/lib/github";
8
9
  import { JobPermission, type JobStep } from "projen/lib/github/workflows-model";
9
10
  import { BUN_VERSION } from "./bun-workflow.ts";
10
11
  import { DBXToolsTypeScriptProject, projectRepositoryUrl } from "./project-js.ts";
@@ -176,28 +177,27 @@ export const UNIFFI_RELEASE_TARGETS: readonly UniFFIReleaseTarget[] = [
176
177
  const RUST_CACHE_ENV = {
177
178
  CARGO_INCREMENTAL: "0",
178
179
  CARGO_TERM_COLOR: "always",
179
- RUSTC_WRAPPER: "sccache",
180
- SCCACHE_GHA_ENABLED: "true",
181
180
  } as const;
182
181
  const UBRN_VERSION = "0.31.0-5";
183
182
  const RELEASE_PLATFORMS_ENV = "DBX_TOOLS_RELEASE_PLATFORMS";
184
183
 
185
- function rustCacheSteps(sharedKey: string, idPrefix = ""): readonly Record<string, unknown>[] {
184
+ function rustCacheSteps(
185
+ sharedKey: string,
186
+ idPrefix = "",
187
+ saveIf = true,
188
+ ): readonly Record<string, unknown>[] {
186
189
  return [
187
190
  {
188
- name: "Setup sccache",
189
- id: `${idPrefix}sccache`,
190
- uses: "mozilla-actions/sccache-action@v0.0.11",
191
- },
192
- {
193
- name: "Cache Cargo registry",
191
+ name: "Cache Cargo registry and targets",
194
192
  id: `${idPrefix}cargo_cache`,
195
193
  uses: "Swatinem/rust-cache@v2.9.2",
196
194
  with: {
197
- "cache-targets": false,
195
+ "cache-targets": true,
196
+ "cache-workspace-crates": false,
198
197
  "add-job-id-key": false,
199
- "add-rust-environment-hash-key": false,
198
+ "add-rust-environment-hash-key": true,
200
199
  "shared-key": sharedKey,
200
+ "save-if": saveIf,
201
201
  },
202
202
  },
203
203
  ];
@@ -842,10 +842,112 @@ export class DBXToolsRustWorkspace {
842
842
  }
843
843
  project.removeTask("rs:bindings:demo");
844
844
  if (releaseEnabled) {
845
+ this.addCacheWorkflow(project, options, nativeTargets);
845
846
  this.addReleaseWorkflow(project, options, nativeTargets);
846
847
  }
847
848
  }
848
849
 
850
+ private addCacheWorkflow(
851
+ project: javascript.NodeProject,
852
+ options: DBXToolsRustWorkspaceOptions,
853
+ targets: readonly UniFFIReleaseTarget[],
854
+ ): void {
855
+ if (!project.github || !isDBXToolsJavaScriptProject()(project) || targets.length === 0) return;
856
+ const releaseRustVersion = options.releaseRustVersion ?? "stable";
857
+ const usePreinstalledWindowsRust = releaseRustVersion === "stable";
858
+ const usesCargoLock = existsSync(join(project.outdir, "Cargo.lock"));
859
+ const hasReleaseExclusions = this.packages.some(
860
+ (pkg) => pkg.packageOptions.releaseExcludeOs?.length,
861
+ );
862
+ const matrix = targets.map((target) => ({
863
+ ...target,
864
+ ...(hasReleaseExclusions
865
+ ? {
866
+ cargoExcludes: this.packages
867
+ .filter((pkg) => pkg.packageOptions.releaseExcludeOs?.includes(target.os))
868
+ .map((pkg) => `--exclude ${pkg.crateName}`)
869
+ .join(" "),
870
+ }
871
+ : {}),
872
+ }));
873
+ const workflow = new GithubWorkflow(project.github, "rust-cache", {
874
+ fileName: "rust-cache.yml",
875
+ limitConcurrency: true,
876
+ concurrencyOptions: { group: "rust-cache", cancelInProgress: true },
877
+ });
878
+ workflow.on({
879
+ push: {
880
+ branches: ["main"],
881
+ paths: [
882
+ ".cargo/**",
883
+ ".github/workflows/rust-cache.yml",
884
+ "Cargo.lock",
885
+ "Cargo.toml",
886
+ "packages/rs/**",
887
+ ],
888
+ },
889
+ workflowDispatch: {},
890
+ });
891
+ workflow.addJob("prime", {
892
+ name: "${{ matrix.node }}",
893
+ runsOn: ["${{ matrix.runner }}"],
894
+ permissions: { contents: JobPermission.READ },
895
+ env: RUST_CACHE_ENV,
896
+ strategy: {
897
+ failFast: false,
898
+ matrix: { include: matrix },
899
+ },
900
+ steps: [
901
+ { name: "Checkout", uses: "actions/checkout@v6" },
902
+ {
903
+ name: "Setup Rust",
904
+ ...(usePreinstalledWindowsRust ? { if: "${{ matrix.os != 'win32' }}" } : {}),
905
+ uses: `dtolnay/rust-toolchain@${releaseRustVersion}`,
906
+ with: { targets: "${{ matrix.cargo }}" },
907
+ },
908
+ ...(usePreinstalledWindowsRust
909
+ ? [
910
+ {
911
+ name: "Verify preinstalled Windows Rust",
912
+ if: "${{ matrix.os == 'win32' }}",
913
+ shell: "bash",
914
+ run: [
915
+ "rustc --version --verbose",
916
+ "cargo --version",
917
+ 'rustup target list --installed | grep -Fx "${{ matrix.cargo }}"',
918
+ 'test -f "$(rustc --print sysroot)/lib/rustlib/${{ matrix.cargo }}/bin/rust-lld.exe"',
919
+ ].join("\n"),
920
+ },
921
+ ]
922
+ : []),
923
+ ...rustCacheSteps(`release-\${{ matrix.cargo }}-rust-${releaseRustVersion}`),
924
+ {
925
+ name: "Install Linux native dependencies",
926
+ if: "${{ matrix.os == 'linux' }}",
927
+ run: [
928
+ "sudo rm -f /etc/apt/sources.list.d/google-chrome.list",
929
+ "sudo apt-get update",
930
+ "sudo apt-get install --yes libdbus-1-dev pkg-config",
931
+ ].join("\n"),
932
+ },
933
+ {
934
+ name: "Prime Cargo target cache",
935
+ shell: "bash",
936
+ env: {
937
+ CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER:
938
+ "${{ matrix.os == 'win32' && 'rust-lld' || '' }}",
939
+ },
940
+ run: timedBash(
941
+ "rust_cache",
942
+ `cargo build --release --workspace${usesCargoLock ? " --locked" : ""} --target "\${{ matrix.cargo }}"${
943
+ hasReleaseExclusions ? " ${{ matrix.cargoExcludes }}" : ""
944
+ }`,
945
+ ),
946
+ },
947
+ ],
948
+ });
949
+ }
950
+
849
951
  private addReleaseWorkflow(
850
952
  project: javascript.NodeProject,
851
953
  options: DBXToolsRustWorkspaceOptions,
@@ -1011,7 +1113,6 @@ export class DBXToolsRustWorkspace {
1011
1113
  permissions: { contents: JobPermission.READ },
1012
1114
  env: {
1013
1115
  ...RUST_CACHE_ENV,
1014
- SCCACHE_GHA_VERSION: `release-\${{ matrix.cargo }}-rust-${releaseRustVersion}`,
1015
1116
  },
1016
1117
  strategy: {
1017
1118
  failFast: false,
@@ -1041,15 +1142,13 @@ export class DBXToolsRustWorkspace {
1041
1142
  },
1042
1143
  ]
1043
1144
  : []),
1044
- ...rustCacheSteps(`release-\${{ matrix.cargo }}-rust-${releaseRustVersion}`),
1145
+ ...rustCacheSteps(`release-\${{ matrix.cargo }}-rust-${releaseRustVersion}`, "", false),
1045
1146
  {
1046
1147
  name: "Log cache configuration",
1047
1148
  shell: "bash",
1048
1149
  run: [
1049
1150
  `echo "cargo_cache_namespace=release-\${{ matrix.cargo }}-rust-${releaseRustVersion}"`,
1050
1151
  'echo "cargo_cache_hit=${{ steps.cargo_cache.outputs.cache-hit }}"',
1051
- 'echo "sccache_scope=${{ github.ref }}"',
1052
- 'echo "sccache_namespace=${SCCACHE_GHA_VERSION}"',
1053
1152
  ].join("\n"),
1054
1153
  },
1055
1154
  {
@@ -1095,12 +1194,6 @@ export class DBXToolsRustWorkspace {
1095
1194
  ]
1096
1195
  : []),
1097
1196
  ...artifactSteps,
1098
- {
1099
- name: "Log sccache statistics",
1100
- if: "${{ always() }}",
1101
- shell: "bash",
1102
- run: '"${SCCACHE_PATH}" --show-stats',
1103
- },
1104
1197
  ],
1105
1198
  };
1106
1199
  const workflow = releaseWorkflow(project);