Skip to content

Commit

Permalink
fix(ios): allow apps with non-arm64 modules to be built on Apple Sili…
Browse files Browse the repository at this point in the history
…con (#13029)

Fixes TIMOB-28525
  • Loading branch information
hansemannn authored Sep 6, 2021
1 parent 010843c commit 3559744
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6928,7 +6928,7 @@ iOSBuilder.prototype.optimizeFiles = function optimizeFiles(next) {
], next);
};

iOSBuilder.prototype.invokeXcodeBuild = function invokeXcodeBuild(next) {
iOSBuilder.prototype.invokeXcodeBuild = async function invokeXcodeBuild(next) {
if (!this.forceRebuild) {
this.logger.info(__('Skipping xcodebuild'));
return next();
Expand Down Expand Up @@ -7096,8 +7096,8 @@ iOSBuilder.prototype.invokeXcodeBuild = function invokeXcodeBuild(next) {
}
// Exclude arm64 architecture from simulator build in XCode 12+ - TIMOB-28042
if (this.legacyModules.size > 0 && parseFloat(this.xcodeEnv.version) >= 12.0) {
if (process.arch === 'arm64') {
return next(new Error('The app is using native modules that do not support arm64 simulators and you are on an arm64 device.'));
if (await processArchitecture() === 'arm64') {
return next(new Error(`The app is using native modules that do not support arm64 simulators and you are on an arm64 device:\n- ${Array.from(this.legacyModules).join('\n- ')}`));
}
this.logger.warn(`The app is using native modules (${Array.from(this.legacyModules)}) that do not support arm64 simulators, we will exclude arm64. This may fail if you're on an arm64 Apple Silicon device.`);
args.push('EXCLUDED_ARCHS=arm64');
Expand Down Expand Up @@ -7142,6 +7142,23 @@ function sha1(value) {
return crypto.createHash('sha1').update(value).digest('hex');
}

// This function has the advantage to detect bridges architectures
// like x86_64 in Rosetta mode (process.arch would still print "arm64" in that case)
async function processArchitecture() {
return new Promise((resolve, reject) => {
// eslint-disable-next-line security/detect-child-process
const exec = require('child_process').exec;

exec('uname -m', function (error, stdout) {
if (error) {
reject(error);
return;
}
resolve(stdout.trim());
});
});
}

// create the builder instance and expose the public api
(function (iosBuilder) {
exports.config = iosBuilder.config.bind(iosBuilder);
Expand Down

0 comments on commit 3559744

Please sign in to comment.