Skip to content

Commit 1c18ec0

Browse files
More robust cmake usage iOS (#695)
1 parent 755acc2 commit 1c18ec0

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

Modules/@babylonjs/react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"readmeFilename": "README.md",
2727
"dependencies": {
2828
"base-64": "^0.1.0",
29+
"cmake-runtime": "3.31.0",
2930
"semver": "^7.3.2"
3031
},
3132
"peerDependencies": {
@@ -35,7 +36,6 @@
3536
"react-native-permissions": ">=3.0.0"
3637
},
3738
"devDependencies": {
38-
"cmake-runtime": "3.31.0",
3939
"@babel/core": "^7.8.4",
4040
"@babel/runtime": "^7.8.4",
4141
"@babylonjs/core": ">=5.53.1",

Modules/@babylonjs/react-native/postinstall.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
const os = require("os");
2+
const path = require("path");
3+
4+
function getCmakeExecutable() {
5+
try {
6+
// cmake-runtime ships the cmake binary; resolve it directly to avoid
7+
// relying on npx or PATH.
8+
const pkgDir = path.dirname(require.resolve('cmake-runtime/package.json'));
9+
const pkg = require('cmake-runtime/package.json');
10+
// cmake-runtime exposes the binary path via its "bin" field
11+
const binRelative = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin['cmake'];
12+
return path.join(pkgDir, binRelative);
13+
} catch (e) {
14+
// Fall back to a cmake on PATH (e.g. homebrew or system install)
15+
return 'cmake';
16+
}
17+
}
218

319
function iosCMake() {
420
const { spawn } = require('child_process');
521

6-
const cmake = spawn('npx', [
7-
'cmake',
8-
'-S', 'ios',
9-
'-B', 'Build/iOS',
22+
const cmake = spawn(getCmakeExecutable(), [
23+
'-S', path.join(__dirname, 'ios'),
24+
'-B', path.join(__dirname, 'Build/iOS'),
1025
'-G', 'Xcode',
11-
], { stdio: 'inherit' });
26+
], { stdio: 'inherit', cwd: __dirname });
1227

1328
cmake.on('exit', code => {
1429
if (code !== 0) {

0 commit comments

Comments
 (0)