cpp.js 2.0.0-beta.2 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,34 @@
1
- /* eslint-disable default-param-last */
2
- /* eslint-disable no-param-reassign */
1
+
2
+
3
3
  import state from '../state/index.js';
4
+ import { getFilteredTargetSpec } from './target.js';
4
5
 
5
- function getRecursiveData(obj, config, dependency, field, platform, subPlatform) {
6
- const platformName = subPlatform ? `${platform}-${subPlatform}` : platform;
7
- if (dependency?.platform?.[platformName]?.[field]) {
8
- Object.entries(dependency.platform[platformName][field]).forEach(([dKey, value]) => {
9
- if (field === 'data') {
10
- const key = `${dependency.paths.project}/dist/prebuilt/${platform}/${dKey}`;
11
- obj[key] = value;
6
+ function getRecursiveData(obj, config, dependency, field, target) {
7
+ const entryArray = getFilteredTargetSpec(dependency?.targetSpecs, target).map(s => s[field]);
8
+ const entries = Object.assign({}, ...entryArray);
9
+ Object.entries(entries).forEach(([dKey, value]) => {
10
+ if (field === 'data') {
11
+ const key = `${dependency.paths.project}/dist/prebuilt/${target.path}/${dKey}`;
12
+ obj[key] = value;
13
+ } else {
14
+ if (typeof value === 'object' && Array.isArray(value)) {
15
+ obj[dKey] = [...(obj[dKey] || []), ...value];
16
+ } else if (typeof value === 'object') {
17
+ obj[dKey] = { ...(obj[dKey] || {}), ...value };
12
18
  } else {
13
- if (typeof value === 'object' && Array.isArray(value)) {
14
- obj[dKey] = [...(obj[dKey] || []), ...value];
15
- } else if (typeof value === 'object') {
16
- obj[dKey] = {...(obj[dKey] || {}), ...value};
17
- } else {
18
- obj[dKey] = value;
19
- }
19
+ obj[dKey] = value;
20
20
  }
21
- });
22
- }
21
+ }
22
+ });
23
23
 
24
24
  dependency.dependencies.forEach((dep) => {
25
- getRecursiveData(obj, config, dep, field, platform, subPlatform);
25
+ getRecursiveData(obj, config, dep, field, target);
26
26
  });
27
27
  }
28
28
 
29
- export default function getData(field, platform = 'Emscripten-x86_64', subPlatform) {
29
+ export default function getData(field, target) {
30
30
  const output = {};
31
- getRecursiveData(output, state.config, state.config, field, platform, subPlatform);
31
+ getRecursiveData(output, state.config, state.config, field, target);
32
32
 
33
33
  return output;
34
34
  }
@@ -1,15 +1,21 @@
1
1
  import findFiles from '../utils/findFiles.js';
2
2
  import state from '../state/index.js';
3
+ import { getFilteredTargetSpec } from './target.js';
3
4
 
4
- export default function getDependLibs() {
5
+ export default function getDependLibs(target) {
5
6
  let dependLibs = [
6
- ...findFiles(`${state.config.paths.build}/Source-Release/Emscripten-x86_64/dependencies/**/*.a`, { cwd: state.config.paths.project }),
7
+ ...findFiles(`${state.config.paths.build}/Source-Release/${target.path}/dependencies/**/*.a`, { cwd: state.config.paths.project }),
7
8
  ];
8
- state.config.dependencyParameters.cmakeDepends.forEach((d) => {
9
+ state.config.dependencyParameters.getCmakeDepends(target).forEach((d) => {
9
10
  if (d.export.libName) {
11
+ const ignoreLibNames = getFilteredTargetSpec(d?.targetSpecs).map(s => s.ignoreLibName).flat();
10
12
  d.export.libName.forEach((fileName) => {
11
- if (d.platform['Emscripten-x86_64'].ignoreLibName?.includes(fileName)) return;
12
- dependLibs.push(...findFiles(`${d.paths.output}/prebuilt/Emscripten-x86_64/lib/lib${fileName}.a`, { cwd: d.paths.project }));
13
+ if (ignoreLibNames?.includes(fileName)) return;
14
+ let libPaths = findFiles(`${d.paths.output}/prebuilt/${target.path}/lib/lib${fileName}.a`, { cwd: d.paths.project });
15
+ if (libPaths.length === 0) {
16
+ libPaths = findFiles(`${d.paths.output}/prebuilt/${target.releasePath}/lib/lib${fileName}.a`, { cwd: d.paths.project });
17
+ }
18
+ dependLibs.push(...libPaths);
13
19
  });
14
20
  }
15
21
  });
@@ -79,14 +79,13 @@ const iosParams = [
79
79
  '-e', `LDFLAGS="${IOS_HOST_FLAGS}"`,
80
80
  ]; */
81
81
 
82
- export default function run(program, params = [], platformPrefix = null, platform = null, dockerOptions = {}) {
83
- const buildPath = platformPrefix ? `${state.config.paths.build}/${platformPrefix}/${platform}` : state.config.paths.build;
82
+ export default function run(program, params = [], platformPrefix = null, target = null, dockerOptions = {}) {
83
+ const buildPath = platformPrefix ? `${state.config.paths.build}/${platformPrefix}/${target.path}` : state.config.paths.build;
84
84
  if (!fs.existsSync(buildPath)) {
85
85
  fs.mkdirSync(buildPath, { recursive: true });
86
86
  }
87
87
 
88
- const [basePlatform, ...arch] = (platform || 'unknown-unknown').split('-'); // Emscripten-x86_64, Android-arm64-v8a, iOS-iphoneos, iOS-iphonesimulator
89
- if (basePlatform !== 'iOS' || program !== null) {
88
+ if (target.platform !== 'ios' || program !== null) {
90
89
  pullDockerImage();
91
90
  }
92
91
 
@@ -94,30 +93,30 @@ export default function run(program, params = [], platformPrefix = null, platfor
94
93
  let dParams = params;
95
94
  let platformParams = [];
96
95
  if (program === null) {
97
- switch (basePlatform) {
98
- case 'Emscripten':
96
+ switch (target.platform) {
97
+ case 'wasm':
99
98
  platformParams = ['-e', 'CXXFLAGS=-fwasm-exceptions', '-e', 'CFLAGS=-fwasm-exceptions'];
100
99
  if (params[0].includes('configure')) dProgram = 'emconfigure';
101
100
  else if (params[0] === 'make') dProgram = 'emmake';
102
101
  else if (params[0] === 'cmake') dProgram = 'emcmake';
103
102
  else if (params[0] === 'cc') dProgram = 'emcc';
104
103
  break;
105
- case 'Android':
104
+ case 'android':
106
105
  [dProgram, ...dParams] = params;
107
- platformParams = arch[0] === 'x86_64' ? androidParamsX86_64 : androidParamsArm64;
106
+ platformParams = target.arch === 'x86_64' ? androidParamsX86_64 : androidParamsArm64;
108
107
  if (dProgram === 'cmake') {
109
108
  dParams = [
110
109
  ...dParams,
111
110
  '-DCMAKE_SYSTEM_NAME=Android', '-DCMAKE_SYSTEM_VERSION=33',
112
- `-DCMAKE_ANDROID_ARCH_ABI=${arch[0] === 'x86_64' ? 'x86_64' : 'arm64-v8a'}`,
111
+ `-DCMAKE_ANDROID_ARCH_ABI=${target.arch === 'x86_64' ? 'x86_64' : 'arm64-v8a'}`,
113
112
  `-DCMAKE_ANDROID_NDK=${ANDROID_NDK}`,
114
113
  `-DANDROID_NDK=${ANDROID_NDK}`,
115
114
  ];
116
115
  }
117
116
  break;
118
- case 'iOS':
117
+ case 'ios':
119
118
  [dProgram, ...dParams] = params;
120
- platformParams = [...iosParams, ...(arch[0] === 'iphoneos' ? IOS_IPHONE_PARAMS : IOS_SIM_PARAMS)];
119
+ platformParams = [...iosParams, ...(target.arch === 'iphoneos' ? IOS_IPHONE_PARAMS : IOS_SIM_PARAMS)];
121
120
  if (dProgram === 'cmake') {
122
121
  platformParams = [];
123
122
  if (dParams[0] !== '--build' && dParams[0] !== '--install') {
@@ -130,10 +129,10 @@ export default function run(program, params = [], platformPrefix = null, platfor
130
129
  '-DCMAKE_SYSTEM_NAME=iOS',
131
130
  `-DMACOSX_FRAMEWORK_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
132
131
  `-DCMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
133
- `-DCMAKE_OSX_SYSROOT='${arch[0] === 'iphoneos' ? iosSdkPath : iosSimSdkPath}'`,
134
- `-DCMAKE_OSX_ARCHITECTURES=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
135
- `-DCMAKE_C_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
136
- `-DCMAKE_CXX_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
132
+ `-DCMAKE_OSX_SYSROOT='${target.arch === 'iphoneos' ? iosSdkPath : iosSimSdkPath}'`,
133
+ `-DCMAKE_OSX_ARCHITECTURES=${target.arch === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
134
+ `-DCMAKE_C_FLAGS=${target.arch === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
135
+ `-DCMAKE_CXX_FLAGS=${target.arch === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
137
136
  '-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=\'iPhone Developer\'',
138
137
  `-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=${state.config.system.XCODE_DEVELOPMENT_TEAM}`,
139
138
  ];
@@ -145,8 +144,8 @@ export default function run(program, params = [], platformPrefix = null, platfor
145
144
  dParams = [
146
145
  ...dParams,
147
146
  `-DCMAKE_TOOLCHAIN_FILE='${state.config.paths.cli}/assets/ios.toolchain.cmake'`,
148
- `-DPLATFORM=${arch[0] === 'iphoneos' ? 'OS64' : 'SIMULATORARM64'}`,
149
- `-DARCHS=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
147
+ `-DPLATFORM=${target.arch === 'iphoneos' ? 'OS64' : 'SIMULATORARM64'}`,
148
+ `-DARCHS=${target.arch === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
150
149
  '-DENABLE_BITCODE=TRUE',
151
150
  '-DBUILD_SHARED_LIBS=OFF',
152
151
  '-DFRAMEWORK=TRUE',
@@ -154,10 +153,10 @@ export default function run(program, params = [], platformPrefix = null, platfor
154
153
  '-DCMAKE_SYSTEM_NAME=iOS',
155
154
  `-DMACOSX_FRAMEWORK_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
156
155
  `-DCMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER=org.js.cpp.${state.config.general.name}`,
157
- `-DCMAKE_OSX_SYSROOT='${arch[0] === 'iphoneos' ? iosSdkPath : iosSimSdkPath}'`,
158
- `-DCMAKE_OSX_ARCHITECTURES=${arch[0] === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
159
- `-DCMAKE_C_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
160
- `-DCMAKE_CXX_FLAGS=${arch[0] === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
156
+ `-DCMAKE_OSX_SYSROOT='${target.arch === 'iphoneos' ? iosSdkPath : iosSimSdkPath}'`,
157
+ `-DCMAKE_OSX_ARCHITECTURES=${target.arch === 'iphoneos' ? 'arm64;arm64e' : 'arm64;x86_64'}`,
158
+ `-DCMAKE_C_FLAGS=${target.arch === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
159
+ `-DCMAKE_CXX_FLAGS=${target.arch === 'iphoneos' ? '-fembed-bitcode' : '-fembed-bitcode-marker'}`,
161
160
  '-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=\'iPhone Developer\'',
162
161
  `-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=${state.config.system.XCODE_DEVELOPMENT_TEAM}`,
163
162
  ];
@@ -170,7 +169,7 @@ export default function run(program, params = [], platformPrefix = null, platfor
170
169
 
171
170
  const env = {};
172
171
  let runner = 'DOCKER';
173
- if ((basePlatform === 'iOS' && program === null) || state.config.system.RUNNER === 'LOCAL') {
172
+ if ((target.platform === 'ios' && program === null) || state.config.system.RUNNER === 'LOCAL') {
174
173
  runner = 'LOCAL';
175
174
  }
176
175
 
@@ -0,0 +1,53 @@
1
+ import state from '../state/index.js';
2
+
3
+ export function getTargetParams(givenTargetParams = {}, noParamCheck = false) {
4
+ const { platform, arch, runtime, buildType, runtimeEnv } = givenTargetParams;
5
+ if (!noParamCheck && (
6
+ (state.config.target.platform && platform && platform !== 'all' && state.config.target.platform !== platform)
7
+ || (state.config.target.arch && arch && arch !== 'all' && state.config.target.arch !== arch)
8
+ || (state.config.target.runtime && runtime && runtime !== 'all' && state.config.target.runtime !== runtime)
9
+ || (state.config.target.buildType && buildType && buildType !== 'all' && state.config.target.buildType !== buildType)
10
+ || (state.config.target.runtimeEnv && runtimeEnv && runtimeEnv !== 'all' && state.config.target.runtimeEnv !== runtimeEnv)
11
+ )) {
12
+ throw new Error('Invalid target parameters');
13
+ }
14
+ return {
15
+ platform: state.config.target.platform || platform || 'all',
16
+ arch: state.config.target.arch || arch || 'all',
17
+ runtime: state.config.target.runtime || runtime || 'all',
18
+ buildType: state.config.target.buildType || buildType || 'all',
19
+ runtimeEnv: state.config.target.runtimeEnv || runtimeEnv || 'all',
20
+ };
21
+ }
22
+
23
+ export function getBuildTargets(targetParams) {
24
+ const { platform, arch, runtime, buildType, runtimeEnv } = targetParams;
25
+ return state.targets.filter(t => (
26
+ (platform === 'all' || t.platform === platform)
27
+ && (arch === 'all' || t.arch === arch)
28
+ && (runtime === 'all' || t.runtime === runtime)
29
+ && (buildType === 'all' || t.buildType === buildType)
30
+ && (runtimeEnv === 'all' || t.runtimeEnv === runtimeEnv)
31
+ ));
32
+ }
33
+
34
+ export function getFilteredBuildTargets(targetParams, targetFilter) {
35
+ const buildTargets = getBuildTargets(targetParams);
36
+ return buildTargets.filter(t => (
37
+ (!targetFilter.platform || t.platform === targetFilter.platform)
38
+ && (!targetFilter.arch || t.arch === targetFilter.arch)
39
+ && (!targetFilter.runtime || t.runtime === targetFilter.runtime)
40
+ && (!targetFilter.buildType || t.buildType === targetFilter.buildType)
41
+ && (!targetFilter.runtimeEnv || t.runtimeEnv === targetFilter.runtimeEnv)
42
+ ));
43
+ }
44
+
45
+ export function getFilteredTargetSpec(targetSpecs, target) {
46
+ return targetSpecs?.filter(t => (
47
+ (!t.platform || t.platform === target.platform)
48
+ && (!t.arch || t.arch === target.arch)
49
+ && (!t.runtime || t.runtime === target.runtime)
50
+ && (!t.buildType || t.buildType === target.buildType)
51
+ && (!t.runtimeEnv || t.runtimeEnv === target.runtimeEnv)
52
+ ))?.map(t => t?.specs)?.filter(t => t) || [];
53
+ }
@@ -2,18 +2,6 @@ cmake_minimum_required(VERSION 3.25)
2
2
  set(CMAKE_CXX_STANDARD 17)
3
3
  project("${PROJECT_NAME}")
4
4
 
5
- if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
6
- if (CMAKE_OSX_SYSROOT MATCHES "/iPhoneOS.platform/")
7
- set(PACKAGE_HOST "iOS-iphoneos")
8
- elseif(CMAKE_OSX_SYSROOT MATCHES "/iPhoneSimulator.platform/")
9
- set(PACKAGE_HOST "iOS-iphonesimulator")
10
- else()
11
- set(PACKAGE_HOST "iOS-unknown")
12
- endif()
13
- else()
14
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
15
- endif()
16
-
17
5
  option(BUILD_BRIDGE "Build Bridge" OFF)
18
6
  option(BUILD_SOURCE "Build Source" OFF)
19
7
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable import/no-unresolved */
2
2
  /* eslint-disable import/first */
3
- /* eslint-disable no-restricted-syntax */
4
- /* eslint-disable no-undef */
3
+
4
+
5
5
  import Module from 'cpp.js/module';
6
6
  import systemConfig from 'cpp.js/systemConfig';
7
7
 
@@ -79,15 +79,14 @@ function initCppJs(userConfig = {}) {
79
79
  ({ ENV }) => {
80
80
  if (ENV && config && config.env) {
81
81
  Object.entries(config.env).forEach(([key, value]) => {
82
- // eslint-disable-next-line no-param-reassign
83
- ENV[key] = value;
82
+ ENV[key] = value?.replace('_CPPJS_DATA_PATH_', `/cppjs`);
84
83
  });
85
84
  }
86
85
  },
87
86
  ],
88
87
  onRuntimeInitialized() {
89
- // m.FS.mkdir(VIRTUAL_PATH);
90
- // m.FS.mkdir(AUTO_MOUNTED_PATH);
88
+ m.FS.mkdir(VIRTUAL_PATH);
89
+ m.FS.mkdir(AUTO_MOUNTED_PATH);
91
90
  if (config.onRuntimeInitialized) config.onRuntimeInitialized(m);
92
91
  },
93
92
  generateVirtualPath() {
@@ -0,0 +1,14 @@
1
+ require "json"
2
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
3
+
4
+ Pod::Spec.new do |s|
5
+ s.module_name = "___PROJECT_NAME___"
6
+ s.name = "___PROJECT_NAME___"
7
+ s.version = package["nativeVersion"]
8
+ s.summary = "___PROJECT_NAME___ package"
9
+ s.homepage = "https://cpp.js.org"
10
+ s.author = "___PROJECT_NAME___ Authors"
11
+ s.source = { :http => "https://cpp.js.org" }
12
+ s.vendored_frameworks = ___PROJECT_FRAMEWORKS___
13
+ s.resources = ___PROJECT_RESOURCES___
14
+ end
@@ -1,23 +1,10 @@
1
- if(ANDROID)
2
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_ANDROID_ARCH_ABI}")
3
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
4
- elseif(APPLE)
5
- if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
6
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/../..")
7
- else()
8
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
9
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
10
- endif()
11
- elseif(UNIX)
12
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
13
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
14
- else()
15
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
16
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
1
+ set(MY_LIST "___PROJECT_HOST___")
2
+ LIST(FIND MY_LIST "${PROJECT_TARGET_HOST}" PACKAGE_HOST_INDEX)
3
+ if(PACKAGE_HOST_INDEX EQUAL -1)
4
+ set(PROJECT_TARGET_HOST "${PROJECT_TARGET_HOST_RELEASE}")
17
5
  endif()
6
+ LIST(FIND MY_LIST "${PROJECT_TARGET_HOST}" PACKAGE_HOST_INDEX)
18
7
 
19
- set(MY_LIST "___PROJECT_HOST___")
20
- LIST(FIND MY_LIST "${PACKAGE_HOST}" PACKAGE_HOST_INDEX)
21
8
  if(NOT PACKAGE_HOST_INDEX EQUAL -1)
22
9
  cmake_minimum_required(VERSION 3.28)
23
10
  set(CMAKE_CXX_STANDARD 11)
@@ -25,22 +12,10 @@ if(NOT PACKAGE_HOST_INDEX EQUAL -1)
25
12
  set(PROJECT_LIBS "___PROJECT_LIBS___")
26
13
  project("${PROJECT_NAME}")
27
14
 
28
- if(ANDROID)
29
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_ANDROID_ARCH_ABI}")
30
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
31
- elseif(APPLE)
32
- if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
33
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/../..")
34
- else()
35
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
36
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
37
- endif()
38
- elseif(UNIX)
39
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
40
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
15
+ if (APPLE AND CMAKE_SYSTEM_NAME STREQUAL "iOS")
16
+ set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/../..")
41
17
  else()
42
- set(PACKAGE_HOST "${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
43
- set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/lib")
18
+ set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PROJECT_TARGET_HOST}/lib")
44
19
  endif()
45
20
 
46
21
  set(PROJECT_LIBS_DIR)
@@ -61,6 +36,6 @@ if(NOT PACKAGE_HOST_INDEX EQUAL -1)
61
36
  target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_LIBS_DIR}")
62
37
 
63
38
  if(NOT APPLE)
64
- target_include_directories("${PROJECT_NAME}" INTERFACE "${PROJECT_SOURCE_DIR}/${PACKAGE_HOST}/include")
39
+ target_include_directories("${PROJECT_NAME}" INTERFACE "${PROJECT_SOURCE_DIR}/${PROJECT_TARGET_HOST}/include")
65
40
  endif()
66
41
  endif()
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable import/no-unresolved */
2
2
  /* eslint-disable import/first */
3
- /* eslint-disable no-restricted-syntax */
4
- /* eslint-disable no-undef */
3
+
4
+
5
5
 
6
6
  import Module from 'cpp.js/module';
7
7
  import systemConfig from 'cpp.js/systemConfig';
@@ -77,7 +77,7 @@ function initCppJs(userConfig = {}) {
77
77
  ({ ENV }) => {
78
78
  if (ENV && config && config.env) {
79
79
  Object.entries(config.env).forEach(([key, value]) => {
80
- // eslint-disable-next-line no-param-reassign
80
+
81
81
  ENV[key] = value;
82
82
  });
83
83
  }
@@ -87,7 +87,7 @@ function initCppJs(userConfig = {}) {
87
87
  if (config.onRuntimeInitialized) config.onRuntimeInitialized(m);
88
88
  },
89
89
  getPreloadedPackage(packageName) {
90
- // eslint-disable-next-line global-require
90
+
91
91
  const a = require('fs').readFileSync(`./${packageName}`, { flag: 'r' }).buffer;
92
92
  return a;
93
93
  },
package/src/bin.js CHANGED
@@ -11,10 +11,11 @@ import createLib from './actions/createLib.js';
11
11
  import buildWasm from './actions/buildWasm.js';
12
12
  import createXCFramework from './actions/createXCFramework.js';
13
13
  import runCppjsApp from './actions/run.js';
14
+ import { getBuildTargets, getFilteredBuildTargets, getFilteredTargetSpec } from './actions/target.js';
15
+
14
16
  import downloadAndExtractFile from './utils/downloadAndExtractFile.js';
15
17
  import writeJson from './utils/writeJson.js';
16
18
  import systemKeys from './utils/systemKeys.js';
17
-
18
19
  import { getDockerImage } from './utils/pullDockerImage.js';
19
20
  import { getContentHash } from './utils/hash.js';
20
21
  import findFiles from './utils/findFiles.js';
@@ -31,7 +32,11 @@ program
31
32
 
32
33
  const commandBuild = program.command('build')
33
34
  .description('compile the project that was set up using Cpp.js')
34
- .addOption(new Option('-p, --platform <platform>', 'target platform').default('All').choices(['All', 'WebAssembly', 'Android', 'iOS']));
35
+ .addOption(new Option('-p, --platform <platform>', 'target platform').default('all').choices(['all', 'wasm', 'android', 'ios']))
36
+ .addOption(new Option('-a, --arch <arch>', 'target architecture').default('all').choices(['all', 'wasm32', 'wasm64', 'x86_64', 'arm64-v8a', 'iphoneos', 'iphonesimulator']))
37
+ .addOption(new Option('-r, --runtime <runtime>', 'target runtime').default('all').choices(['all', 'st', 'mt']))
38
+ .addOption(new Option('-b, --build-type <buildType>', 'target build type').default('release').choices(['all', 'release', 'debug']))
39
+ .addOption(new Option('-re, --runtime-env <runtimeEnv>', 'target runtime environment').default('all').choices(['all', 'browser', 'node']));
35
40
 
36
41
  const commandDocker = program.command('docker')
37
42
  .description('manage docker');
@@ -54,11 +59,14 @@ program.parse(process.argv);
54
59
 
55
60
  switch (program.args[0]) {
56
61
  case 'build': {
57
- const { platform } = commandBuild.opts();
62
+ const targetParams = commandBuild.opts();
63
+ if (targetParams.platform === 'wasm' && targetParams.arch === 'all') {
64
+ targetParams.arch = 'wasm32';
65
+ }
58
66
  if (state.config.build.withBuildConfig) {
59
- buildExternal(platform);
67
+ buildExternal(targetParams);
60
68
  } else {
61
- build(platform);
69
+ build(targetParams);
62
70
  }
63
71
  break;
64
72
  }
@@ -221,7 +229,7 @@ function run(programName, params) {
221
229
  runCppjsApp(programName, params, null, null, { console: true });
222
230
  }
223
231
 
224
- async function buildExternal(platform) {
232
+ async function buildExternal(targetParams) {
225
233
  const version = state.config.package.nativeVersion;
226
234
  if (!version) {
227
235
  console.error('no version found!');
@@ -245,9 +253,10 @@ async function buildExternal(platform) {
245
253
  });
246
254
  }
247
255
 
248
- buildLib(platform);
256
+ buildLib(targetParams);
249
257
 
250
258
  if (copyToDist) {
259
+ const targets = getBuildTargets(targetParams);
251
260
  Object.entries(copyToDist).forEach(([key, value]) => {
252
261
  const values = [];
253
262
  if (Array.isArray(value)) {
@@ -256,27 +265,33 @@ async function buildExternal(platform) {
256
265
  values.push(value);
257
266
  }
258
267
  values.forEach(v => {
259
- const targetPath = `${state.config.paths.output}/prebuilt/${v}`;
260
- if (!fs.existsSync(targetPath)) {
261
- fs.copyFileSync(`${state.config.paths.project}/${key}`, targetPath);
262
- }
268
+ targets.forEach(target => {
269
+ const assetPath = `${state.config.paths.output}/prebuilt/${target.path}/${v}`;
270
+ if (!fs.existsSync(assetPath)) {
271
+ fs.copyFileSync(`${state.config.paths.project}/${key}`, assetPath);
272
+ }
273
+ });
263
274
  });
264
275
  });
265
276
  }
266
277
  }
267
278
 
268
- async function build(platform) {
269
- buildLib(platform);
270
- if (platform === 'WebAssembly' || platform === 'All') {
271
- createWasmJs();
272
- }
279
+ async function build(targetParams) {
280
+ buildLib(targetParams);
281
+ createWasmJs(targetParams);
273
282
  }
274
283
 
275
- function buildLib(platform) {
284
+ function buildLib(targetParams) {
276
285
  let isChanged = false;
277
- state.platforms[platform].forEach((p) => {
278
- if (!fs.existsSync(`${state.config.paths.output}/prebuilt/${p}/lib`)) {
279
- createLib(p, 'Source', { isProd: true, buildSource: true });
286
+ const targets = getBuildTargets(targetParams);
287
+ if (targets.length === 0) {
288
+ console.error('No targets found for the given parameters.', targetParams);
289
+ throw new Error('No targets found for the given parameters.');
290
+ }
291
+
292
+ targets.forEach((target) => {
293
+ if (!fs.existsSync(`${state.config.paths.output}/prebuilt/${target.path}/lib`)) {
294
+ createLib(target, 'Source', { buildSource: true });
280
295
 
281
296
  const modules = [];
282
297
  state.config.paths.module.forEach((modulePath) => {
@@ -284,32 +299,57 @@ function buildLib(platform) {
284
299
  modules.push(...findFiles('*.i', { cwd: modulePath }));
285
300
  });
286
301
  if (modules.length > 0) {
287
- fs.mkdirSync(`${state.config.paths.output}/prebuilt/${p}/swig`, { recursive: true });
302
+ fs.mkdirSync(`${state.config.paths.output}/prebuilt/${target.path}/swig`, { recursive: true });
288
303
  }
289
304
  modules.forEach((modulePath) => {
290
305
  const fileName = modulePath.split('/').at(-1);
291
- fs.copyFileSync(modulePath, `${state.config.paths.output}/prebuilt/${p}/swig/${fileName}`);
306
+ fs.copyFileSync(modulePath, `${state.config.paths.output}/prebuilt/${target.path}/swig/${fileName}`);
292
307
  });
293
308
  isChanged = true;
294
309
  } else {
295
- console.log(`${state.config.general.name} is already compiled to ${p} architecture.`);
310
+ console.log(`${state.config.general.name} is already compiled to ${target.path} architecture.`);
296
311
  }
297
312
  });
298
313
 
299
314
  if (isChanged && fs.existsSync(`${state.config.paths.build}/Source-Release/prebuilt`)) {
300
315
  fs.cpSync(`${state.config.paths.build}/Source-Release/prebuilt`, `${state.config.paths.output}/prebuilt`, { recursive: true, dereference: true });
301
316
  }
317
+ if (isChanged && fs.existsSync(`${state.config.paths.build}/Source-Debug/prebuilt`)) {
318
+ fs.cpSync(`${state.config.paths.build}/Source-Debug/prebuilt`, `${state.config.paths.output}/prebuilt`, { recursive: true, dereference: true });
319
+ }
302
320
 
303
321
  createXCFramework();
304
322
 
323
+ const iosTargets = getBuildTargets({ platform: 'ios', arch: 'iphoneos', runtime: 'mt', buildType: 'release' });
324
+ const podSpecs = findFiles('*.podspec', { cwd: state.config.paths.project });
325
+ if (podSpecs.length === 0 && targets.length > 0) {
326
+ const iosTarget = iosTargets[0];
327
+ const resources = getFilteredTargetSpec(state.config.targetSpecs, iosTarget).map(s => s.data).filter(s => s).map(d => Object.keys(d)).flat();
328
+ const uniqueResources = [...new Set(resources)].map(r => `dist/prebuilt/${iosTarget.path}/${r}`);
329
+ const xcFrameworks = [];
330
+ xcFrameworks.push(...state.config.export.libName.map((l) => `${l}.xcframework`));
331
+ if (!xcFrameworks.some(f => !fs.existsSync(`${state.config.paths.project}/${f}`))) {
332
+ xcFrameworks.push(...state.config.dependencies.map((d) => d.export.libName.map((l) => `${l}.xcframework`)).flat());
333
+ const distPodSpecContent = fs.readFileSync(`${state.config.paths.cli}/assets/cppjs-package.podspec`, { encoding: 'utf8', flag: 'r' })
334
+ .replaceAll('___PROJECT_NAME___', state.config.general.name)
335
+ .replace('___PROJECT_FRAMEWORKS___', xcFrameworks.map(f => `'${f}'`).join(', '))
336
+ .replace('___PROJECT_RESOURCES___', JSON.stringify(uniqueResources));
337
+ fs.writeFileSync(`${state.config.paths.project}/${state.config.general.name}.podspec`, distPodSpecContent);
338
+ }
339
+ }
340
+
305
341
  const distCmakeContent = fs.readFileSync(`${state.config.paths.cli}/assets/dist.cmake`, { encoding: 'utf8', flag: 'r' })
306
342
  .replace('___PROJECT_NAME___', state.config.general.name)
307
- .replace('___PROJECT_HOST___', state.platforms[platform].join(';'))
343
+ .replace('___PROJECT_HOST___', targets.map((t) => t.path).join(';'))
308
344
  .replace('___PROJECT_LIBS___', state.config.export.libName.join(';'));
309
345
  fs.writeFileSync(`${state.config.paths.output}/prebuilt/CMakeLists.txt`, distCmakeContent);
310
346
  }
311
347
 
312
- async function createWasmJs() {
348
+ async function createWasmJs(targetParams) {
349
+ const targets = getFilteredBuildTargets(targetParams, { platform: 'wasm' });
350
+ if (targets.length === 0) {
351
+ return;
352
+ }
313
353
  let headers = [];
314
354
  state.config.paths.header.forEach((headerPath) => {
315
355
  headers.push(findFiles('**/*.h', { cwd: headerPath }));
@@ -323,30 +363,30 @@ async function createWasmJs() {
323
363
  });
324
364
 
325
365
  const opt = {
326
- isProd: true,
327
366
  buildSource: false,
328
367
  nativeGlob: [
329
368
  `${state.config.paths.cli}/assets/commonBridges.cpp`,
330
369
  ...bridges,
331
370
  ],
332
371
  };
333
- createLib('Emscripten-x86_64', 'Bridge', opt);
334
372
 
335
- await buildWasm('browser', true);
336
- await buildWasm('node', true);
373
+ for (const target of targets) {
374
+ if (fs.existsSync(`${state.config.paths.output}/${target.jsName}`) && fs.existsSync(`${state.config.paths.output}/${target.wasmName}`)) {
375
+ console.log(`${state.config.general.name} wasm is already compiled to ${target.path} ${target.runtimeEnv || ''} architecture.`);
376
+ continue;
377
+ }
378
+ createLib(target, 'Bridge', opt);
379
+ await buildWasm(target);
337
380
 
338
- fs.rmSync(`${state.config.paths.output}/data`, { recursive: true, force: true });
339
- if (fs.existsSync(`${state.config.paths.build}/data`)) {
340
- fs.renameSync(`${state.config.paths.build}/data`, `${state.config.paths.output}/data`);
341
- }
381
+ fs.rmSync(`${state.config.paths.output}/data`, { recursive: true, force: true });
382
+ if (fs.existsSync(`${state.config.paths.build}/data`)) {
383
+ fs.renameSync(`${state.config.paths.build}/data`, `${state.config.paths.output}/data`);
384
+ }
342
385
 
343
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.node.js`, `${state.config.paths.output}/${state.config.general.name}.node.js`);
344
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${state.config.paths.output}/${state.config.general.name}.browser.js`);
345
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.wasm`, `${state.config.paths.output}/${state.config.general.name}.wasm`);
346
- if (fs.existsSync(`${state.config.paths.build}/${state.config.general.name}.data.txt`)) {
347
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.data.txt`, `${state.config.paths.output}/${state.config.general.name}.data.txt`);
386
+ fs.copyFileSync(`${state.config.paths.build}/${target.jsName}`, `${state.config.paths.output}/${target.jsName}`);
387
+ fs.copyFileSync(`${state.config.paths.build}/${target.wasmName}`, `${state.config.paths.output}/${target.wasmName}`);
388
+ if (fs.existsSync(`${state.config.paths.build}/${target.dataTxtName}`)) {
389
+ fs.copyFileSync(`${state.config.paths.build}/${target.dataTxtName}`, `${state.config.paths.output}/${target.dataTxtName}`);
390
+ }
348
391
  }
349
- /* if (fs.existsSync(`${state.config.paths.build}/${state.config.general.name}.js`)) {
350
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.js`, `${state.config.paths.output}/${state.config.general.name}.js`);
351
- } */
352
392
  }
package/src/index.js CHANGED
@@ -9,5 +9,6 @@ export { default as getCmakeParameters } from './actions/getCmakeParameters.js';
9
9
  export { default as createXCFramework } from './actions/createXCFramework.js';
10
10
  export { default as getAllBridges } from './actions/getAllBridges.js';
11
11
  export { default as run } from './actions/run.js';
12
+ export { getTargetParams, getBuildTargets, getFilteredBuildTargets, getFilteredTargetSpec } from './actions/target.js';
12
13
  export { default as getCppJsScript } from './integration/getCppJsScript.js';
13
14
  export { default as getDependFilePath } from './integration/getDependFilePath.js';