Skip to content

Commit

Permalink
fix(ios): exclude arm64 arch for sim target if native modules aren't …
Browse files Browse the repository at this point in the history
…xcframeworks

Modules built before xcframework support do not have an arm64 sim arch/target
To avoid having to break all modules, we'll try and exclude arm64 from sim builds
This will eventually break if app is built on arm64 apple silicon and a new
xcframework based module hasn't been shipped.
  • Loading branch information
sgtcoolguy committed Sep 10, 2020
1 parent 133527e commit faba6e1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,7 @@ iOSBuilder.prototype.validate = function validate(logger, config, cli) {

this.commonJsModules = [];
this.nativeLibModules = [];
this.legacyModules = new Set();

const nativeHashes = [];

Expand Down Expand Up @@ -2202,6 +2203,7 @@ iOSBuilder.prototype.validate = function validate(logger, config, cli) {
module.isFramework = false;

// For Obj-C static libraries, use the .a library or hashing
this.legacyModules.add(module.id); // Record that this won't support macos or arm64 sim!
nativeHashes.push(module.hash = this.hash(fs.readFileSync(module.libFile)));
// Try to load native module as framework (Swift)
} else if (fs.existsSync(path.join(module.modulePath, frameworkName))) {
Expand All @@ -2210,6 +2212,7 @@ iOSBuilder.prototype.validate = function validate(logger, config, cli) {
module.isFramework = true;

// For Swift frameworks, use the binary inside the .framework for hashing
this.legacyModules.add(module.id); // Record that this won't support macos or arm64 sim!
nativeHashes.push(module.hash = this.hash(fs.readFileSync(path.join(module.libFile, this.scrubbedModuleId(module.id)))));
} else if (fs.existsSync(path.join(module.modulePath, xcFrameworkOfLib))) {
module.libName = xcFrameworkOfLib;
Expand All @@ -2221,6 +2224,7 @@ iOSBuilder.prototype.validate = function validate(logger, config, cli) {
if (!fs.existsSync(path.join(module.libFile, archDir))) {
// Try XCode 11 dir w/o arm64 support
archDir = 'ios-i386_x86_64-simulator';
this.legacyModules.add(module.id);// Record that this won't support arm64 sim!
}
// TODO: Change hash calculation
nativeHashes.push(module.hash = this.hash(fs.readFileSync(path.join(module.libFile, archDir, 'lib' + module.id.toLowerCase() + '.a'))));
Expand All @@ -2234,6 +2238,7 @@ iOSBuilder.prototype.validate = function validate(logger, config, cli) {
if (!fs.existsSync(path.join(module.libFile, archDir))) {
// Try XCode 11 dir w/o arm64 support
archDir = 'ios-i386_x86_64-simulator';
this.legacyModules.add(module.id);// Record that this won't support arm64 sim!
}
// TODO: Change hash calculation
nativeHashes.push(module.hash = this.hash(fs.readFileSync(path.join(module.libFile, archDir, this.scrubbedModuleId(module.id) + '.framework', this.scrubbedModuleId(module.id)))));
Expand Down Expand Up @@ -6905,11 +6910,14 @@ iOSBuilder.prototype.invokeXcodeBuild = function invokeXcodeBuild(next) {
if (this.simOnlyActiveArch) {
args.push('ONLY_ACTIVE_ARCH=1');
}
}

// Exclude arm64 architecture from simulator build in XCode 12+ - TIMOB-28042
if (this.target === 'simulator' && parseFloat(this.xcodeEnv.version) >= 12.0) {
args.push('EXCLUDED_ARCHS=arm64');
// 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.'));
}
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');
}
}

xcodebuildHook(
Expand Down

0 comments on commit faba6e1

Please sign in to comment.