@limrun/api 0.34.0 → 0.36.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/index.d.mts +3 -1
  3. package/index.d.mts.map +1 -1
  4. package/index.d.ts +3 -1
  5. package/index.d.ts.map +1 -1
  6. package/index.js +17 -1
  7. package/index.js.map +1 -1
  8. package/index.mjs +2 -0
  9. package/index.mjs.map +1 -1
  10. package/internal/direct-instance-errors.d.mts +9 -0
  11. package/internal/direct-instance-errors.d.mts.map +1 -1
  12. package/internal/direct-instance-errors.d.ts +9 -0
  13. package/internal/direct-instance-errors.d.ts.map +1 -1
  14. package/internal/direct-instance-errors.js +6 -1
  15. package/internal/direct-instance-errors.js.map +1 -1
  16. package/internal/direct-instance-errors.mjs +5 -1
  17. package/internal/direct-instance-errors.mjs.map +1 -1
  18. package/internal/proxy-transport.d.mts +9 -0
  19. package/internal/proxy-transport.d.mts.map +1 -1
  20. package/internal/proxy-transport.d.ts +9 -0
  21. package/internal/proxy-transport.d.ts.map +1 -1
  22. package/internal/proxy-transport.js +19 -0
  23. package/internal/proxy-transport.js.map +1 -1
  24. package/internal/proxy-transport.mjs +19 -0
  25. package/internal/proxy-transport.mjs.map +1 -1
  26. package/internal/sse-fetch.d.mts +11 -0
  27. package/internal/sse-fetch.d.mts.map +1 -0
  28. package/internal/sse-fetch.d.ts +11 -0
  29. package/internal/sse-fetch.d.ts.map +1 -0
  30. package/internal/sse-fetch.js +23 -0
  31. package/internal/sse-fetch.js.map +1 -0
  32. package/internal/sse-fetch.mjs +20 -0
  33. package/internal/sse-fetch.mjs.map +1 -0
  34. package/package.json +21 -1
  35. package/rbe-session.d.mts +35 -0
  36. package/rbe-session.d.mts.map +1 -0
  37. package/rbe-session.d.ts +35 -0
  38. package/rbe-session.d.ts.map +1 -0
  39. package/rbe-session.js +72 -0
  40. package/rbe-session.js.map +1 -0
  41. package/rbe-session.mjs +65 -0
  42. package/rbe-session.mjs.map +1 -0
  43. package/rbe-workspace.d.mts +163 -0
  44. package/rbe-workspace.d.mts.map +1 -0
  45. package/rbe-workspace.d.ts +163 -0
  46. package/rbe-workspace.d.ts.map +1 -0
  47. package/rbe-workspace.js +394 -0
  48. package/rbe-workspace.js.map +1 -0
  49. package/rbe-workspace.mjs +382 -0
  50. package/rbe-workspace.mjs.map +1 -0
  51. package/resources/xcode-instances-helpers.d.mts +61 -0
  52. package/resources/xcode-instances-helpers.d.mts.map +1 -1
  53. package/resources/xcode-instances-helpers.d.ts +61 -0
  54. package/resources/xcode-instances-helpers.d.ts.map +1 -1
  55. package/resources/xcode-instances-helpers.js +126 -7
  56. package/resources/xcode-instances-helpers.js.map +1 -1
  57. package/resources/xcode-instances-helpers.mjs +127 -8
  58. package/resources/xcode-instances-helpers.mjs.map +1 -1
  59. package/src/index.ts +25 -0
  60. package/src/internal/direct-instance-errors.ts +11 -1
  61. package/src/internal/proxy-transport.ts +22 -0
  62. package/src/internal/sse-fetch.ts +20 -0
  63. package/src/rbe-session.ts +92 -0
  64. package/src/rbe-workspace.ts +407 -0
  65. package/src/resources/xcode-instances-helpers.ts +223 -13
  66. package/src/version.ts +1 -1
  67. package/version.d.mts +1 -1
  68. package/version.d.ts +1 -1
  69. package/version.js +1 -1
  70. package/version.mjs +1 -1
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TRY_IMPORT_LINE = exports.LIMRUN_DIR = void 0;
4
+ exports.findBazelWorkspaceRoot = findBazelWorkspaceRoot;
5
+ exports.inferBuildTarget = inferBuildTarget;
6
+ exports.detectBazelMajorVersion = detectBazelMajorVersion;
7
+ exports.isBazel9OrLater = isBazel9OrLater;
8
+ exports.renderXcodeConfigBuild = renderXcodeConfigBuild;
9
+ exports.renderLimrunBazelrc = renderLimrunBazelrc;
10
+ exports.ensureTryImport = ensureTryImport;
11
+ exports.writeRbeWorkspaceFiles = writeRbeWorkspaceFiles;
12
+ const tslib_1 = require("./internal/tslib.js");
13
+ // Mirrored between src/rbe-workspace.ts (canonical) and packages/cli/src/lib/rbe-workspace.ts
14
+ // until the CLI imports it from a published @limrun/api; tests/rbe-copy-sync.test.ts keeps the
15
+ // two copies byte-identical. Apply any edit to both.
16
+ const fs_1 = tslib_1.__importDefault(require("fs"));
17
+ const path_1 = tslib_1.__importDefault(require("path"));
18
+ /**
19
+ * Generates the .limrun/ workspace companion for Limrun remote execution: a Bazel
20
+ * package pinning the remote fleet's Xcode version and an rc fragment with the
21
+ * remote-execution flags under the `limrun` config. The caller learns the
22
+ * fleet's version key from the instance's RBE status, so the generated config
23
+ * always matches the fleet without any user action; regenerating the files
24
+ * after a fleet Xcode upgrade refreshes the pin.
25
+ */
26
+ exports.LIMRUN_DIR = '.limrun';
27
+ exports.TRY_IMPORT_LINE = 'try-import %workspace%/.limrun/bazelrc';
28
+ const TRY_IMPORT_COMMENT = '# Added by Limrun remote-execution setup: loads the generated config.';
29
+ const WORKSPACE_MARKERS = ['MODULE.bazel', 'WORKSPACE', 'WORKSPACE.bazel'];
30
+ /**
31
+ * Finds the Bazel workspace root by walking up from `startDir` to the first
32
+ * ancestor containing a MODULE.bazel / WORKSPACE / WORKSPACE.bazel, mirroring
33
+ * how Bazel itself locates the workspace when run from a subdirectory. Returns
34
+ * null when no workspace is found up to the filesystem root. The generated
35
+ * `.limrun/` and the `try-import` must live at this root, since `%workspace%`
36
+ * in bazelrc resolves here regardless of the directory the build is run from.
37
+ */
38
+ function findBazelWorkspaceRoot(startDir) {
39
+ let dir = path_1.default.resolve(startDir);
40
+ for (;;) {
41
+ if (WORKSPACE_MARKERS.some((m) => fs_1.default.existsSync(path_1.default.join(dir, m)))) {
42
+ return dir;
43
+ }
44
+ const parent = path_1.default.dirname(dir);
45
+ if (parent === dir) {
46
+ return null;
47
+ }
48
+ dir = parent;
49
+ }
50
+ }
51
+ const APP_RULE_RE = /\b(?:ios|macos|tvos|watchos)_application\s*\(/;
52
+ const TARGET_NAME_RE = /^\s*name\s*=\s*"([^"]+)"/;
53
+ const TARGET_SCAN_SKIP_DIRS = new Set(['.git', 'node_modules', '.limrun']);
54
+ /**
55
+ * Best-effort guess of a single buildable app target to show in the printed
56
+ * build command, so it reads `//App` instead of a `//your:target` placeholder.
57
+ * Scans the workspace's BUILD files (buildifier-formatted) for apple
58
+ * `*_application` rules (no bazel invocation) and returns the label in short
59
+ * form (`//pkg` when the target name matches the package's last segment).
60
+ * Returns null when there are zero or multiple candidates (ambiguous → caller
61
+ * keeps the placeholder).
62
+ */
63
+ function inferBuildTarget(workspaceRoot) {
64
+ const found = [];
65
+ const walk = (dir) => {
66
+ if (found.length > 1)
67
+ return; // already ambiguous; stop early
68
+ let entries;
69
+ try {
70
+ entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
71
+ }
72
+ catch {
73
+ return;
74
+ }
75
+ for (const entry of entries) {
76
+ if (entry.isDirectory()) {
77
+ if (TARGET_SCAN_SKIP_DIRS.has(entry.name) || entry.name.startsWith('bazel-'))
78
+ continue;
79
+ walk(path_1.default.join(dir, entry.name));
80
+ }
81
+ else if (entry.name === 'BUILD' || entry.name === 'BUILD.bazel') {
82
+ collectAppTargets(path_1.default.join(dir, entry.name), workspaceRoot, found);
83
+ }
84
+ }
85
+ };
86
+ walk(workspaceRoot);
87
+ return found.length === 1 ? found[0] : null;
88
+ }
89
+ /** Appends `//pkg[:name]` labels of apple application rules in one BUILD file. */
90
+ function collectAppTargets(buildFile, workspaceRoot, out) {
91
+ let content;
92
+ try {
93
+ content = fs_1.default.readFileSync(buildFile, 'utf8');
94
+ }
95
+ catch {
96
+ return;
97
+ }
98
+ const pkg = path_1.default.relative(workspaceRoot, path_1.default.dirname(buildFile)).split(path_1.default.sep).join('/');
99
+ let inAppRule = false;
100
+ for (const line of content.split('\n')) {
101
+ // Skip comment lines so a commented-out `# ios_application(` can't start a
102
+ // phantom rule (and a commented `# name = ...` can't be captured), which
103
+ // would otherwise leave inAppRule set and mislabel a later rule's name.
104
+ if (line.trimStart().startsWith('#'))
105
+ continue;
106
+ if (!inAppRule) {
107
+ if (APP_RULE_RE.test(line))
108
+ inAppRule = true;
109
+ continue;
110
+ }
111
+ const match = line.match(TARGET_NAME_RE);
112
+ if (match) {
113
+ const name = match[1];
114
+ const last = pkg.split('/').pop();
115
+ out.push(pkg === '' || pkg === '.' ? `//:${name}`
116
+ : last === name ? `//${pkg}`
117
+ : `//${pkg}:${name}`);
118
+ inAppRule = false;
119
+ }
120
+ else if (/^\)/.test(line)) {
121
+ inAppRule = false; // rule closed before a name line we could read
122
+ }
123
+ }
124
+ }
125
+ /**
126
+ * Reads the workspace's pinned Bazel major version from `.bazelversion`, or
127
+ * null when the file is absent or its first line has no leading integer.
128
+ *
129
+ * Used to decide whether the generated BUILD must `load` the Xcode rules from
130
+ * apple_support: in Bazel 9 they are no longer native globals and must be
131
+ * loaded, while in Bazel 8 they ARE native globals and the apple_support rule
132
+ * impls `fail()` on the unmigrated Bazel, so loading them there breaks
133
+ * analysis. The generator runs in the workspace on the client, so the file is
134
+ * the authoritative signal for the Bazel that bazelisk will launch.
135
+ */
136
+ function detectBazelMajorVersion(workspaceDir) {
137
+ try {
138
+ const raw = fs_1.default.readFileSync(path_1.default.join(workspaceDir, '.bazelversion'), 'utf8');
139
+ const firstLine = (raw.split('\n', 1)[0] ?? '').trim();
140
+ const match = firstLine.match(/^(\d+)/);
141
+ return match ? Number(match[1]) : null;
142
+ }
143
+ catch {
144
+ return null;
145
+ }
146
+ }
147
+ /**
148
+ * Whether to treat the workspace as Bazel 9+ for RBE config: true when the
149
+ * detected major version is >= 9, OR unknown (no `.bazelversion` means bazelisk
150
+ * runs the latest release, which is 9+). This single predicate decides both
151
+ * emitting the apple_support Xcode-rule loads and surfacing the SHA256 digest
152
+ * hint, so the two stay in lockstep.
153
+ */
154
+ function isBazel9OrLater(bazelMajor) {
155
+ return bazelMajor === null || bazelMajor >= 9;
156
+ }
157
+ /** Major.minor short alias (e.g. "26.4") used for the SDK default and --xcode_version. */
158
+ function shortVersion(versionKey) {
159
+ const parts = versionKey.split('.');
160
+ if (parts.length < 3) {
161
+ throw new Error(`unexpected Xcode version key from the instance: ${versionKey}`);
162
+ }
163
+ return `${parts[0]}.${parts[1]}`;
164
+ }
165
+ /** Renders one xcode_version rule from a major.minor.patch.build version key. */
166
+ function renderXcodeVersionRule(name, versionKey) {
167
+ // shortVersion validates the key shape (major.minor.patch[.build]) and yields
168
+ // the major.minor used for both the SDK defaults and the short alias.
169
+ const sdk = shortVersion(versionKey);
170
+ const parts = versionKey.split('.');
171
+ const fullAlias = `${parts[0]}.${parts[1]}.${parts[2]}`;
172
+ return `xcode_version(
173
+ name = "${name}",
174
+ aliases = [
175
+ "${sdk}",
176
+ "${fullAlias}",
177
+ ],
178
+ default_ios_sdk_version = "${sdk}",
179
+ default_macos_sdk_version = "${sdk}",
180
+ default_tvos_sdk_version = "${sdk}",
181
+ default_watchos_sdk_version = "${sdk}",
182
+ version = "${versionKey}",
183
+ )`;
184
+ }
185
+ /**
186
+ * Renders an `available_xcodes` set with a single member that is also its
187
+ * mandatory default. Both sets the BUILD file emits (remote, local) are
188
+ * single-version sets of this shape, pointing at the same fleet pin.
189
+ */
190
+ function renderAvailableXcodes(name, target) {
191
+ return `available_xcodes(
192
+ name = "${name}",
193
+ default = "${target}",
194
+ versions = ["${target}"],
195
+ )`;
196
+ }
197
+ /**
198
+ * Renders the generated Bazel package pinning the Xcode version to the fleet's.
199
+ *
200
+ * remoteVersionKey is the fleet's `xcodebuild -version` in major.minor.patch.build
201
+ * form (e.g. 26.4.0.17E192).
202
+ *
203
+ * Uses Bazel's remote/local `xcode_config` split with BOTH sets pointing at the
204
+ * SAME fleet pin (rather than a single `default=/versions=` bucket, which
205
+ * resolves with availability UNKNOWN and leaves Apple/Swift actions eligible for
206
+ * local execution). With local == remote, `--xcode_version` resolves as
207
+ * "mutually available" (BOTH), which declares up front that this build uses only
208
+ * the fleet's Xcode AND keeps apple_support from emitting its remote-only
209
+ * "...specified, but it is not available locally..." DEBUG notice (that notice
210
+ * fires only when the pinned version is in `remote_versions` but not
211
+ * `local_versions`).
212
+ *
213
+ * We intentionally do NOT name the client's own local Xcode: under
214
+ * `--config=limrun` every action runs remotely (`--spawn_strategy=remote` +
215
+ * `--noremote_local_fallback`), so a local DEVELOPER_DIR is never resolved.
216
+ * Declaring a distinct local version would only reintroduce that DEBUG notice on
217
+ * a client whose Xcode differs from the fleet's. (The fleet pin is used, not
218
+ * Bazel's `@local_config_xcode//:host_available_xcodes`: that repo is not
219
+ * visible from the main module under bzlmod and is never generated off-darwin.)
220
+ *
221
+ * When `emitLoads` is true (Bazel 9+), the Xcode rules are loaded from
222
+ * apple_support; on Bazel 8 they are native globals and MUST NOT be loaded
223
+ * (the apple_support rule impls fail on the unmigrated Bazel).
224
+ */
225
+ function renderXcodeConfigBuild(remoteVersionKey, emitLoads) {
226
+ // Bazel 9 migrated xcode_version/available_xcodes/xcode_config out of native
227
+ // globals into apple_support; they must be loaded there. The repo_name
228
+ // @build_bazel_apple_support is the apple_support module convention.
229
+ const loads = emitLoads ?
230
+ `load("@build_bazel_apple_support//xcode:xcode_version.bzl", "xcode_version")
231
+ load("@build_bazel_apple_support//xcode:available_xcodes.bzl", "available_xcodes")
232
+ load("@build_bazel_apple_support//xcode:xcode_config.bzl", "xcode_config")
233
+
234
+ `
235
+ : '';
236
+ const remoteRule = renderXcodeVersionRule('remote_xcode', remoteVersionKey);
237
+ return `# Generated by lim xcode rbe. Do not edit; rerun the command to refresh.
238
+ #
239
+ # Pins the Xcode version Bazel uses to the limrun fleet's Xcode, independent of
240
+ # any Xcode installed on this machine. Both the remote and local sets point at
241
+ # the SAME pin so --xcode_version resolves as mutually available (no
242
+ # apple_support remote-only DEBUG notice); under --config=limrun all actions run
243
+ # remotely, so a local DEVELOPER_DIR is never resolved. Selected via
244
+ # .limrun/bazelrc (--config=limrun).
245
+ ${loads}${remoteRule}
246
+
247
+ # Both sets point at the single fleet pin.
248
+ ${renderAvailableXcodes('remote_xcodes', ':remote_xcode')}
249
+
250
+ ${renderAvailableXcodes('local_xcodes', ':remote_xcode')}
251
+
252
+ xcode_config(
253
+ name = "remote_xcode_config",
254
+ remote_versions = ":remote_xcodes",
255
+ local_versions = ":local_xcodes",
256
+ )
257
+ `;
258
+ }
259
+ /**
260
+ * Renders the rc fragment with the remote-execution flags under
261
+ * --config=limrun.
262
+ *
263
+ * - `--remote_cache=` (empty) clears any workspace-level `--remote_cache`. The
264
+ * limrun executor carries its own CAS, so a separate cache backend (e.g. a
265
+ * repo pointing `--remote_cache` at BuildBuddy/EngFlow) splits inputs and
266
+ * outputs across two stores the executor cannot reconcile, surfacing as "Lost
267
+ * inputs no longer available remotely". Emptying it under --config=limrun
268
+ * routes caching back to the executor's CAS while leaving the repo's non-limrun
269
+ * builds (where that cache is valid) untouched.
270
+ * - The `--bes_*` flags stream the Build Event Protocol to the daemon's BES
271
+ * service, co-hosted on the same RBE frontend as the executor (hence the same
272
+ * `127.0.0.1:${port}`), powering the live + persisted console.
273
+ * `--bes_upload_mode=nowait_for_upload_complete` keeps the current build from
274
+ * blocking at exit on the BES upload (the wait moves to the start of the next
275
+ * invocation, bounded by `--bes_timeout`), while streams stay complete/acked
276
+ * for the persisted record. An older daemon without the BES service registered
277
+ * answers PublishBuildEvent with a non-fatal warning, so the flags are safe
278
+ * ahead of the image rollout.
279
+ * - `--xcode_version` pins the fleet's version: without it, a mac client
280
+ * lacking that exact version has no mutual version and silently falls back
281
+ * to its LOCAL default, shipping the wrong version to the remote worker via
282
+ * XCODE_VERSION_OVERRIDE (the worker then rejects it).
283
+ * - `--strategy=SwiftCompile=remote` / `--strategy=Genrule=remote` override
284
+ * mnemonic-specific strategies a workspace may pin (rules_swift defaults
285
+ * SwiftCompile to a local persistent `worker`; repos often pin Genrule to
286
+ * `standalone`). Those run locally and break RBE: a local Swift worker can't
287
+ * run on a Linux client at all, and on a mac it would demand the fleet's
288
+ * Xcode locally. --spawn_strategy=remote does not override per-mnemonic
289
+ * pins, so these explicit overrides are required.
290
+ * - `--ios_multi_cpus=sim_arm64` pins the app to the **arm64 iOS simulator**.
291
+ * Limrun's Mac fleet (workers and the attached simulators) is Apple Silicon,
292
+ * so the build product must be arm64. Without this, the simulator cpu follows
293
+ * the CLIENT's Bazel default (`sim_arm64` on an Apple Silicon Mac, but
294
+ * `x86_64` on an Intel Mac or a Linux client), and an x86_64 app installed on
295
+ * the arm64 fleet simulator fails to launch with "needs to be updated by the
296
+ * developer to work on this version of iOS". The pin makes the artifact match
297
+ * the fleet regardless of where bazel runs (the whole point of RBE).
298
+ * - PATH includes /usr/sbin:/sbin so genrules that probe `sysctl` (e.g.
299
+ * `hw.logicalcpu` for `make -j`) resolve it on the worker.
300
+ * - `--remote_download_outputs=minimal` keeps the built .ipa in the instance's
301
+ * CAS instead of downloading it; the daemon auto-installs it server-side from
302
+ * there (driven by the BES stream), so the bytes never round-trip. The printed
303
+ * `lim xcode rbe` output tells users to add `--remote_download_outputs=toplevel`
304
+ * on the command line when they want the .ipa materialized locally (a
305
+ * command-line flag overrides this rc setting).
306
+ * - `--extra_execution_platforms` is emitted ONLY for non-mac clients: a Linux
307
+ * host has no auto-detected darwin execution platform, so the Apple/Swift
308
+ * toolchain (exec_compatible_with macos) needs one registered to route
309
+ * actions to the mac RBE pool. On a mac it is HARMFUL: it makes bazel run
310
+ * exec-config actions on the local host instead of the remote worker, which
311
+ * then demand a local Xcode.
312
+ * - `--modify_execution_info=.*=-no-remote,.*=-no-remote-exec` strips the
313
+ * `no-remote`/`no-remote-exec` execution-info tags rules_apple sets on
314
+ * bundling/linking/signing actions (in-code on device builds, and via its
315
+ * recommended `+no-remote` bazelrc that real iOS repos carry). Under
316
+ * --config=limrun every action runs remotely, so any such tag leaves the
317
+ * action with no usable strategy ("cannot be executed with any of the
318
+ * available strategies: [remote]") and the build fails. That is the exact
319
+ * breakage a Linux client (no local Xcode) hits. This is the execution-info
320
+ * analog of the --strategy=...=remote overrides above; stripping globally is
321
+ * safe because removing a tag an action never had is a no-op.
322
+ * - A `user.limrun.bazelrc` at the workspace root is try-imported last as a user
323
+ * override hook, so callers can extend or override the generated config
324
+ * without editing this file or passing flags on the command line.
325
+ */
326
+ function renderLimrunBazelrc(port, versionKey, isMacClient) {
327
+ const execPlatform = isMacClient ? '' : ('build:limrun --extra_execution_platforms=@build_bazel_apple_support//platforms:darwin_arm64\n');
328
+ return `# Generated by lim xcode rbe. Do not edit; rerun the command to refresh.
329
+ build:limrun --remote_executor=grpc://127.0.0.1:${port}
330
+ build:limrun --bes_backend=grpc://127.0.0.1:${port}
331
+ build:limrun --bes_upload_mode=nowait_for_upload_complete
332
+ build:limrun --bes_timeout=60s
333
+ build:limrun --remote_cache=
334
+ build:limrun --remote_default_exec_properties=OSFamily=Darwin
335
+ build:limrun --spawn_strategy=remote
336
+ build:limrun --noremote_local_fallback
337
+ build:limrun --strategy=SwiftCompile=remote
338
+ build:limrun --strategy=Genrule=remote
339
+ build:limrun --modify_execution_info=.*=-no-remote,.*=-no-remote-exec
340
+ build:limrun --xcode_version_config=//.limrun:remote_xcode_config
341
+ build:limrun --xcode_version=${shortVersion(versionKey)}
342
+ build:limrun --ios_multi_cpus=sim_arm64
343
+ build:limrun --remote_download_outputs=minimal
344
+ ${execPlatform}build:limrun --action_env=PATH=/usr/bin:/bin:/usr/sbin:/sbin
345
+
346
+ # A user.limrun.bazelrc at the workspace root is try-imported last, so it can
347
+ # extend or override anything above without editing this generated file or
348
+ # passing flags on the command line. A missing file is silently skipped.
349
+ try-import %workspace%/user.limrun.bazelrc
350
+ `;
351
+ }
352
+ /**
353
+ * Idempotently ensures the workspace .bazelrc try-imports the generated
354
+ * fragment. Creates .bazelrc when missing. Returns true when the file changed.
355
+ */
356
+ function ensureTryImport(workspaceDir) {
357
+ const bazelrcPath = path_1.default.join(workspaceDir, '.bazelrc');
358
+ let current = '';
359
+ if (fs_1.default.existsSync(bazelrcPath)) {
360
+ current = fs_1.default.readFileSync(bazelrcPath, 'utf8');
361
+ // Match the try-import on a line basis (exact, uncommented) rather than a
362
+ // raw substring, so a commented-out occurrence (e.g. `# try-import ...`)
363
+ // doesn't make us skip wiring the active import.
364
+ const alreadyWired = current.split('\n').some((line) => line.trim() === exports.TRY_IMPORT_LINE);
365
+ if (alreadyWired) {
366
+ return false;
367
+ }
368
+ }
369
+ const block = `${TRY_IMPORT_COMMENT}\n${exports.TRY_IMPORT_LINE}\n`;
370
+ const next = current === '' ? block : `${current.replace(/\n*$/, '\n\n')}${block}`;
371
+ fs_1.default.writeFileSync(bazelrcPath, next);
372
+ return true;
373
+ }
374
+ /**
375
+ * Writes .limrun/{BUILD,bazelrc,.gitignore} into the workspace and wires the
376
+ * try-import. The .gitignore containing "*" makes the directory self-ignoring
377
+ * so nothing else in the user's repo needs to change.
378
+ */
379
+ function writeRbeWorkspaceFiles(workspaceDir, xcodeVersionKey, port, isMacClient = process.platform === 'darwin', bazelMajor = detectBazelMajorVersion(workspaceDir)) {
380
+ const dir = path_1.default.join(workspaceDir, exports.LIMRUN_DIR);
381
+ fs_1.default.mkdirSync(dir, { recursive: true });
382
+ const buildFile = path_1.default.join(dir, 'BUILD');
383
+ const bazelrcFragment = path_1.default.join(dir, 'bazelrc');
384
+ // Load the Xcode rules from apple_support on Bazel 9+, where they are no
385
+ // longer native globals. On a known Bazel 8 workspace they ARE native (and
386
+ // loading would fail), so omit the loads.
387
+ const emitLoads = isBazel9OrLater(bazelMajor);
388
+ fs_1.default.writeFileSync(buildFile, renderXcodeConfigBuild(xcodeVersionKey, emitLoads));
389
+ fs_1.default.writeFileSync(bazelrcFragment, renderLimrunBazelrc(port, xcodeVersionKey, isMacClient));
390
+ fs_1.default.writeFileSync(path_1.default.join(dir, '.gitignore'), '*\n');
391
+ const bazelrcUpdated = ensureTryImport(workspaceDir);
392
+ return { buildFile, bazelrcFragment, bazelrcUpdated };
393
+ }
394
+ //# sourceMappingURL=rbe-workspace.js.map
@@ -0,0 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