Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync, spawn } from 'child_process';
import { execSync } from 'child_process';
import * as fs from 'fs-extra';
import * as ps from 'path';
import * as os from 'os';
import { CocosParams } from '../base/default';
import { cchelper, toolHelper, Paths } from '../utils';
import { cchelper, toolHelper } from '../utils';
import { MacOSPackTool } from './mac-os';

export interface IOrientation {
Expand Down Expand Up @@ -133,13 +133,8 @@ export default class IOSPackTool extends MacOSPackTool {
throw new Error('Error: Try to build iphoneos application but no developer team id was given!');
}
const nativePrjDir = this.paths.nativePrjDir;

const simulatorArch = this.getIosSimulatorArch();
const projName = this.params.projectName;
const os = require('os');
const cpus = os.cpus();
const model = (cpus && cpus[0] && cpus[0].model) ? cpus[0].model : '';
// check mac architecture
// const platform = /Apple/.test(model) ? `-arch arm64` : `-arch x86_64`;
// get xcode workspace
const regex = new RegExp(projName + '.xcworkspace$');
const files = fs.readdirSync(nativePrjDir);
Expand All @@ -163,7 +158,7 @@ export default class IOSPackTool extends MacOSPackTool {
await toolHelper.runCmake([projCompileParams, '-sdk', 'iphoneos', `-arch arm64`]);
}
if (options.simulator) {
await toolHelper.runCmake([projCompileParams, '-sdk', 'iphonesimulator', `-arch x86_64`]); //force compile x86_64 app for iPhone simulator on Mac
await toolHelper.runCmake([projCompileParams, '-sdk', 'iphonesimulator', `-arch ${simulatorArch}`]);
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,51 @@ export abstract class MacOSPackTool extends NativePackTool {
return /Apple/.test(model) && process.platform === 'darwin';
}

protected getXcodeMajorVerion(): number {
protected compareVersion(a: string, b: string): number {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这在 utils 模块里已经有工具方法了,看看是不是可以直接使用?

@oahcy oahcy Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来的compareVersion不通用, 这个方法统一改下,地方有点多,后面再提个pr。

const aParts = a.split('.').map((part) => Number.parseInt(part, 10) || 0);
const bParts = b.split('.').map((part) => Number.parseInt(part, 10) || 0);
const maxLength = Math.max(aParts.length, bParts.length);

for (let i = 0; i < maxLength; i++) {
const aValue = aParts[i] ?? 0;
const bValue = bParts[i] ?? 0;
if (aValue !== bValue) {
return aValue - bValue;
}
}

return 0;
}

protected getXcodeVersion(): string {
try {
const output = execSync('xcrun xcodebuild -version').toString('utf8');
return Number.parseInt(output.match(/Xcode\s(\d+)\.\d+/)![1]);
const match = output.match(/Xcode\s+(\d+(?:\.\d+)+)/);
return match?.[1] || '0.0';
} catch (e) {
console.error(e);
return '0.0';
}
}

protected getXcodeMajorVerion(): number {
try {
return Number.parseInt(this.getXcodeVersion().split('.')[0] || '0', 10);
} catch (e) {
console.error(e);
// fallback to default Xcode version
return 11;
}
}

protected getIosSimulatorArch(): 'arm64' | 'x86_64' {
// Xcode 14.3+ no longer supports running iOS Simulator under Rosetta on Apple Silicon.
if (this.isAppleSilicon() && this.compareVersion(this.getXcodeVersion(), '14.3') >= 0) {
return 'arm64';
}
return 'x86_64';
}

async modifyXcodeProject() {
if (this.params.platformParams.skipUpdateXcodeProject) {
if (this.getXcodeMajorVerion() < 12) {
Expand Down
4 changes: 2 additions & 2 deletions workflow/download-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const tools = {
essential: true,
},
{
url: 'http://download.cocos.com/CocosSDK/tools/cmake-3.24.3-windows-x86_64.zip',
url: 'http://download.cocos.com/CocosSDK/tools/cmake-4.4.2-windows-x86_64.zip',
dist: 'cmake',
essential: true,
},
Expand Down Expand Up @@ -110,7 +110,7 @@ const tools = {
essential: true,
},
{
url: 'http://download.cocos.com/CocosSDK/tools/cmake-3.24.3-macos-universal.zip',
url: 'http://download.cocos.com/CocosSDK/tools/cmake-4.4.2-macos-universal.zip',
dist: 'cmake',
essential: true,
},
Expand Down
Loading