Cross-Platform Build (--emulated) on Apple M1

Greetings, Team!

I recently procured a much-anticipated Mac Studio - and found myself with my first Mac with Apple silicon. My Studio has the M1 Max - but I’ll presume all the various M1 variants behave the same.

I read with interest this thread regarding Balena CLI on m2/m1 Macs - and also found a very similar thread regarding Raspberry Pi build error on M1 Mac - and I suspect these are all closely related (or identical) issues, regarding the ‘emulation’ required to build for a target platform, from another.

In my recent case, I was revisiting the Balena CLI Masterclass after installing the CLI. I get to step 5.1, where the --emulated build happens. On my Studio, this step runs for awhile, and then just hangs. To confirm / validate - I executed the same steps on an Intel-based MBP (same OS [Ventura], same version of Balena CLI [14.5.15]) - and it worked fine.

I created an Issue over on the GitHub repo for the Masterclass - but as suggested, am posting here for better visibility and engagement.

can you tried building without --emulated flag as m1 is an arm processor?

1 Like

@ja-ilija Brilliant!

That did the trick.

billy@MacStudio balena-cli-masterclass % balena build --fleet cliFleet
[Info]    No "docker-compose.yml" file found at "/Users/billy/code/balena/balena-cli-masterclass"
[Info]    Creating default composition with source: "/Users/billy/code/balena/balena-cli-masterclass"
[Build]   Building services...
[Build]   main Preparing...
[Info]    Building for aarch64/raspberrypi4-64
[Build]   main Step 1/6 : FROM balenalib/raspberrypi4-64-node:8
[Build]   main  ---> a3865ad22f08
[Build]   main Step 2/6 : WORKDIR /usr/src/app
[Build]   main  ---> Using cache
[Build]   main  ---> 7088009ff539
[Build]   main Step 3/6 : COPY package.json package-lock.json ./
[Build]   main  ---> Using cache
[Build]   main  ---> 853d16f8a3a8
[Build]   main Step 4/6 : RUN npm install --ci --production     && npm cache clean --force     && rm -rf /tmp/*
[Build]   main  ---> Using cache
[Build]   main  ---> d70e546840ce
[Build]   main Step 5/6 : COPY src/ ./src/
[Build]   main  ---> Using cache
[Build]   main  ---> b98e7f30d0db
[Build]   main Step 6/6 : CMD ["npm", "start"]
[Build]   main  ---> Using cache
[Build]   main  ---> b1607da4bcff
[Build]   main Successfully built b1607da4bcff
[Build]   main Successfully tagged balena-cli-masterclass_main:latest
[Build]   main Image size: 220.28 MB
[Build]   Built 1 service in 0:02
[Success] Build succeeded!

I almost wrote in my original post: “It seems given that Apple silicon uses an ARM architecture, it would be even easier to emulate…” - but I never imagined that the architectures would be similar enough that code built on an Apple M1 would run on a Rasberry Pi. :slight_smile:

Shows what I don’t know! :smiley:

Thank you for helping me realize the obvious. Off to update the GitHub issue…