Skip to content

Commit f10a829

Browse files
GarothhugelungAndrei Eternal
authored
Warn about rosetta on osx in build-protos (RooCodeInc#3400)
* warn about rosetta on osx in build-protos * make one console log better * format --------- Co-authored-by: Andrei Edell <[email protected]> Co-authored-by: Andrei Eternal <[email protected]>
1 parent da12437 commit f10a829

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

proto/build-proto.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,44 @@ import { fileURLToPath } from "url"
66
import { execSync } from "child_process"
77
import { globby } from "globby"
88
import chalk from "chalk"
9+
import os from "os"
910

1011
import { createRequire } from "module"
1112
const require = createRequire(import.meta.url)
1213
const protoc = path.join(require.resolve("grpc-tools"), "../bin/protoc")
1314

15+
// Check for Apple Silicon compatibility
16+
function checkAppleSiliconCompatibility() {
17+
// Only run check on macOS
18+
if (process.platform !== "darwin") {
19+
return
20+
}
21+
22+
// Check if running on Apple Silicon
23+
const cpuArchitecture = os.arch()
24+
if (cpuArchitecture === "arm64") {
25+
try {
26+
// Check if Rosetta is installed
27+
const rosettaCheck = execSync('/usr/bin/pgrep oahd || echo "NOT_INSTALLED"').toString().trim()
28+
29+
if (rosettaCheck === "NOT_INSTALLED") {
30+
console.log(chalk.yellow("Detected Apple Silicon (ARM64) architecture."))
31+
console.log(
32+
chalk.red("Rosetta 2 is NOT installed. The npm version of protoc is not compatible with Apple Silicon."),
33+
)
34+
console.log(chalk.cyan("Please install Rosetta 2 using the following command:"))
35+
console.log(chalk.cyan(" softwareupdate --install-rosetta --agree-to-license"))
36+
console.log(chalk.red("Aborting build process."))
37+
process.exit(1)
38+
} else {
39+
console.log(chalk.green("Rosetta 2 is installed. Continuing with build."))
40+
}
41+
} catch (error) {
42+
console.log(chalk.yellow("Could not determine Rosetta installation status. Proceeding anyway."))
43+
}
44+
}
45+
}
46+
1447
const __filename = fileURLToPath(import.meta.url)
1548
const SCRIPT_DIR = path.dirname(__filename)
1649
const ROOT_DIR = path.resolve(SCRIPT_DIR, "..")
@@ -42,6 +75,9 @@ const serviceDirs = Object.keys(serviceNameMap).map((serviceKey) => path.join(RO
4275
async function main() {
4376
console.log(chalk.bold.blue("Starting Protocol Buffer code generation..."))
4477

78+
// Check for Apple Silicon compatibility before proceeding
79+
checkAppleSiliconCompatibility()
80+
4581
// Define output directories
4682
const TS_OUT_DIR = path.join(ROOT_DIR, "src", "shared", "proto")
4783

0 commit comments

Comments
 (0)