Skip to content

Commit 60a35e1

Browse files
committed
add functions.isEnabled to config
1 parent 77d720f commit 60a35e1

File tree

7 files changed

+59
-57
lines changed

7 files changed

+59
-57
lines changed

cppjs-core/cpp.js/src/actions/createInterface.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import state, { saveCache } from '../state/index.js';
55
import { getFileHash } from '../utils/hash.js';
66
import run from './run.js';
77

8-
export default function createBridgeFile(headerOrModuleFilePath) {
8+
export default function createBridgeFile(headerOrModuleFilePath, platform = 'Emscripten-x86_64') {
99
const interfaceFilePath = upath.resolve(headerOrModuleFilePath);
1010
if (!fs.existsSync(`${state.config.paths.build}/interface`)) {
1111
fs.mkdirSync(`${state.config.paths.build}/interface`, { recursive: true });
1212
}
1313
if (!fs.existsSync(`${state.config.paths.build}/bridge`)) {
1414
fs.mkdirSync(`${state.config.paths.build}/bridge`, { recursive: true });
1515
}
16-
const interfaceFile = createInterfaceFile(interfaceFilePath);
17-
return createBridgeFileFromInterfaceFile(interfaceFile);
16+
const interfaceFile = createInterfaceFile(interfaceFilePath, platform);
17+
return createBridgeFileFromInterfaceFile(interfaceFile, platform);
1818
}
1919

20-
function createInterfaceFile(headerOrModuleFilePath) {
20+
function createInterfaceFile(headerOrModuleFilePath, platform) {
2121
if (!headerOrModuleFilePath) {
2222
return null;
2323
}
@@ -37,7 +37,7 @@ function createInterfaceFile(headerOrModuleFilePath) {
3737
return newPath;
3838
}
3939

40-
const headerPaths = (state.config.dependencyParameters?.pathsOfCmakeDepends?.split(';') || [])
40+
const headerPaths = (state.config.dependencyParameters?.getCmakeDependsPathAndName(platform).pathsOfCmakeDepends || [])
4141
.filter((d) => d.startsWith(state.config.paths.base));
4242

4343
const temp2 = headerPaths
@@ -92,7 +92,7 @@ function createInterfaceFile(headerOrModuleFilePath) {
9292
return outputFilePath;
9393
}
9494

95-
function createBridgeFileFromInterfaceFile(interfaceFilePath) {
95+
function createBridgeFileFromInterfaceFile(interfaceFilePath, platform) {
9696
if (!interfaceFilePath) {
9797
return null;
9898
}
@@ -105,8 +105,8 @@ function createBridgeFileFromInterfaceFile(interfaceFilePath) {
105105
const allHeaders = state.config.dependencyParameters.headerPathWithDepends.split(';');
106106

107107
let includePath = [
108-
...state.config.allDependencies.map((d) => `${d.paths.output}/prebuilt/Emscripten-x86_64/include`),
109-
...state.config.allDependencies.map((d) => `${d.paths.output}/prebuilt/Emscripten-x86_64/swig`),
108+
...state.config.allDependencies.map((d) => `${d.paths.output}/prebuilt/${platform}/include`),
109+
...state.config.allDependencies.map((d) => `${d.paths.output}/prebuilt/${platform}/swig`),
110110
...state.config.paths.header,
111111
...allHeaders,
112112
].filter((path) => !!path.toString()).map((path) => `-I${path}`);

cppjs-core/cpp.js/src/actions/getCmakeParameters.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ export default function getCmakeParameters(platform, options = {}) {
3939

4040
const cmakeCompileOptions = [...new Set(getData('cmake', platform)?.compileOptions || [])];
4141

42-
const pathsOfCmakeDepends = dependParams.pathsOfCmakeDepends.split(';');
43-
const nameOfCmakeDepends = dependParams.nameOfCmakeDepends.split(';');
44-
const pathsOfCmakeDependsFilteredByPlatform = [];
45-
const nameOfCmakeDependsFilteredByPlatform = [];
46-
pathsOfCmakeDepends.forEach((d, i) => {
47-
if (fs.existsSync(`${d}/${platform}`) || (basePlatform === 'iOS' && fs.existsSync(`${d}/../../${nameOfCmakeDepends[i]}.xcframework`))) {
48-
pathsOfCmakeDependsFilteredByPlatform.push(d);
49-
nameOfCmakeDependsFilteredByPlatform.push(nameOfCmakeDepends[i]);
50-
}
51-
});
52-
5342
params.push(...[
5443
`-DPROJECT_NAME=${options.name || state.config.general.name}`,
5544
`-DBASE_DIR=${state.config.paths.project}`,
@@ -58,8 +47,8 @@ export default function getCmakeParameters(platform, options = {}) {
5847
`-DNATIVE_GLOB=${nativeGlob.join(';')}`,
5948
`-DHEADER_GLOB=${headerGlob.join(';')}`,
6049
`-DHEADER_DIR=${headerDirs.join(';')}`,
61-
`-DDEPENDS_CMAKE_PATHS=${pathsOfCmakeDependsFilteredByPlatform.join(';')}`,
62-
`-DDEPENDS_CMAKE_NAMES=${nameOfCmakeDependsFilteredByPlatform.join(';')}`,
50+
`-DDEPENDS_CMAKE_PATHS=${dependParams.getCmakeDependsPathAndName(platform).pathsOfCmakeDepends.join(';')}`,
51+
`-DDEPENDS_CMAKE_NAMES=${dependParams.getCmakeDependsPathAndName(platform).nameOfCmakeDepends.join(';')}`,
6352
`-DBRIDGE_DIR=${state.config.paths.build}/bridge`,
6453
`-DBUILD_TYPE=${buildType}`,
6554
`-DBUILD_${otherBuildType}_LIBS=OFF`,

cppjs-core/cpp.js/src/actions/getDependLibs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function getDependLibs() {
55
let dependLibs = [
66
...findFiles(`${state.config.paths.build}/Source-Release/Emscripten-x86_64/dependencies/**/*.a`, { cwd: state.config.paths.project }),
77
];
8-
state.config.dependencyParameters.cmakeDepends.forEach((d) => {
8+
state.config.dependencyParameters.getCmakeDepends('Emscripten-x86_64').forEach((d) => {
99
if (d.export.libName) {
1010
d.export.libName.forEach((fileName) => {
1111
if (d.platform['Emscripten-x86_64'].ignoreLibName?.includes(fileName)) return;

cppjs-core/cpp.js/src/state/calculateDependencyParameters.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,32 @@ export default function calculateDependencyParameters(config) {
2727
setPath(cmakeDepends, config, 'this', cmakeFilter);
2828
cmakeDepends = [...new Set(cmakeDepends)];
2929

30-
const pathsOfCmakeDepends = [];
31-
const nameOfCmakeDepends = [];
32-
cmakeDepends.forEach((d) => {
33-
const dependPath = getParentPath(d.paths.cmake);
34-
if (!pathsOfCmakeDepends.includes(dependPath)) {
35-
pathsOfCmakeDepends.push(dependPath);
36-
nameOfCmakeDepends.push(d.general.name);
37-
}
38-
});
30+
const getCmakeDepends = (platform, variants = []) => {
31+
return cmakeDepends.filter(d => d.functions.isEnabled(platform, variants));
32+
};
33+
34+
const getCmakeDependsPathAndName = (platform, variants = []) => {
35+
const pathsOfCmakeDepends = [];
36+
const nameOfCmakeDepends = [];
37+
getCmakeDepends(platform, variants).forEach((d) => {
38+
const dependPath = d.paths.cmakeDir;
39+
if (!pathsOfCmakeDepends.includes(dependPath)) {
40+
pathsOfCmakeDepends.push(dependPath);
41+
nameOfCmakeDepends.push(d.general.name);
42+
}
43+
});
44+
return {
45+
pathsOfCmakeDepends: pathsOfCmakeDepends,
46+
nameOfCmakeDepends: nameOfCmakeDepends,
47+
};
48+
}
3949

4050
return {
4151
nativeGlob,
4252
headerGlob,
4353
headerPathWithDepends,
44-
cmakeDepends,
45-
pathsOfCmakeDepends: pathsOfCmakeDepends.join(';'),
46-
nameOfCmakeDepends: nameOfCmakeDepends.join(';'),
54+
getCmakeDepends,
55+
getCmakeDependsPathAndName,
4756
};
4857
}
4958

@@ -62,9 +71,3 @@ function setPath(arr, dependency, type, filter = () => { }) {
6271
setPath(arr, dep, type, filter);
6372
});
6473
}
65-
66-
function getParentPath(path) {
67-
const pathArray = path.split('/');
68-
pathArray.pop();
69-
return pathArray.join('/');
70-
}

cppjs-core/cpp.js/src/state/loadConfig.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os from 'node:os';
2+
import fs from 'node:fs';
23
import systemKeys from '../utils/systemKeys.js';
34
import loadJs from '../utils/loadJs.js';
45
import loadJson from '../utils/loadJson.js';
@@ -42,6 +43,7 @@ function getFilledConfig(config, options = { isDepend: false }) {
4243
build: config.build || {},
4344
extensions: config.extensions || [],
4445
package: null,
46+
functions: config.functions || {},
4547
};
4648

4749
if (newConfig.paths.config && !newConfig.paths.project) {
@@ -114,6 +116,13 @@ function getFilledConfig(config, options = { isDepend: false }) {
114116
newConfig.build.usePthread = newConfig.allDependencies.some((d) => d?.build?.usePthread);
115117
}
116118

119+
newConfig.functions.isEnabled = newConfig.functions.isEnabled || ((platform) => {
120+
return (
121+
fs.existsSync(`${newConfig.paths.cmakeDir}/${platform}`)
122+
|| (basePlatform === 'iOS' && fs.existsSync(`${newConfig.paths.cmakeDir}/../../${newConfig.general.name}.xcframework`))
123+
);
124+
});
125+
117126
newConfig.dependencyParameters = calculateDependencyParameters(newConfig);
118127
// newConfig.cmakeParameters = getCmakeParameters(newConfig);
119128

cppjs-packages/cppjs-package-gdal/cppjs-package-gdal-android-multithread/cppjs.config.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import webpAndroidMultithread from '@cpp.js/package-webp-android-multithread/cpp
1010
import zlibAndroidMultithread from '@cpp.js/package-zlib-android-multithread/cppjs.config.js';
1111

1212
export default {
13-
dependencies: [
14-
expatAndroidMultithread,
15-
geosAndroidMultithread,
16-
geotiffAndroidMultithread,
17-
iconvAndroidMultithread,
18-
projAndroidMultithread,
19-
spatialiteAndroidMultithread,
20-
sqlite3AndroidMultithread,
21-
tiffAndroidMultithread,
22-
webpAndroidMultithread,
23-
zlibAndroidMultithread,
24-
],
13+
dependencies: [
14+
expatAndroidMultithread,
15+
geosAndroidMultithread,
16+
geotiffAndroidMultithread,
17+
iconvAndroidMultithread,
18+
projAndroidMultithread,
19+
spatialiteAndroidMultithread,
20+
sqlite3AndroidMultithread,
21+
tiffAndroidMultithread,
22+
webpAndroidMultithread,
23+
zlibAndroidMultithread,
24+
],
2525
general: {
2626
name: 'gdal'
2727
},
@@ -48,5 +48,5 @@ export default {
4848
CPL_LOG_ERRORS: 'ON'
4949
}
5050
}
51-
}
51+
},
5252
};

cppjs-plugins/cppjs-plugin-webpack/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ export default class CppjsWebpackPlugin {
2727
createLib('Emscripten-x86_64', 'Bridge', { isProd: true, buildSource: false, nativeGlob: [`${state.config.paths.cli}/assets/commonBridges.cpp`, ...this.bridges] });
2828
await buildWasm('browser', true);
2929
if (!isDev) {
30-
fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${compilation.options.output.path}/cpp.js`);
31-
fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.wasm`, `${compilation.options.output.path}/cpp.wasm`);
30+
const output = state.config.paths.output === state.config.paths.build ? compilation.options.output.path : state.config.paths.output;
31+
fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${output}/cpp.js`);
32+
fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.wasm`, `${output}/cpp.wasm`);
3233

3334
const dataFilePath = `${state.config.paths.build}/${state.config.general.name}.data.txt`;
3435
if (fs.existsSync(dataFilePath)) {
35-
fs.copyFileSync(dataFilePath, `${compilation.options.output.path}/cpp.data.txt`);
36+
fs.copyFileSync(dataFilePath, `${output}/cpp.data.txt`);
3637
}
3738
/* const workerFilePath = `${state.config.paths.build}/${state.config.general.name}.js`;
3839
if (fs.existsSync(workerFilePath)) {
39-
fs.copyFileSync(workerFilePath, `${compilation.options.output.path}/cpp.worker.js`);
40+
fs.copyFileSync(workerFilePath, `${output}/cpp.worker.js`);
4041
} */
4142
}
4243
}

0 commit comments

Comments
 (0)