@@ -6,11 +6,44 @@ import { fileURLToPath } from "url"
66import { execSync } from "child_process"
77import { globby } from "globby"
88import chalk from "chalk"
9+ import os from "os"
910
1011import { createRequire } from "module"
1112const require = createRequire ( import . meta. url )
1213const 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+
1447const __filename = fileURLToPath ( import . meta. url )
1548const SCRIPT_DIR = path . dirname ( __filename )
1649const ROOT_DIR = path . resolve ( SCRIPT_DIR , ".." )
@@ -42,6 +75,9 @@ const serviceDirs = Object.keys(serviceNameMap).map((serviceKey) => path.join(RO
4275async 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