Skip to content

Commit 93f9846

Browse files
committed
v1.0.0-alpha.2
1 parent 3a15117 commit 93f9846

File tree

191 files changed

+4828
-14409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+4828
-14409
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ dist
55
tmp
66
.cppjs
77
/out-tsc
8+
*.xcframework
9+
*.xcframework.zip
10+
*.tgz
811

912
# dependencies
1013
node_modules

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LICENSE
2+
*.xcframework.zip

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Buğra Sarı
3+
Copyright (c) 2024 Buğra Sarı
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bind C++ codes to JS on the web and react native without writing extra code.
44

55
> **Note:** This project is currently under heavy development.
66
7-
<https://gdal3.js.org>
7+
<https://cpp.js.org>
88

99
\
1010
**Why Cpp.js?**
@@ -47,4 +47,4 @@ public:
4747
## License
4848
[MIT](https://opensource.org/licenses/MIT)
4949

50-
Copyright (c) 2023-present, Buğra Sarı
50+
Copyright (c) 2024, Buğra Sarı

core/cppjs-core-docker/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "cppjs-docker",
3-
"version": "0.2.6",
3+
"version": "1.0.0-alpha.2",
4+
"private": "true",
45
"scripts": {
56
"build": "docker build --no-cache -t bugra9/cpp.js:latest -t bugra9/cpp.js:0.2.6 .",
67
"push": "docker push bugra9/cpp.js --all-tags"

core/cppjs-core-rn-embind/cpp/src/emscripten/bind.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
#include <any>
2121
#include <unordered_map>
22+
#include <stdlib.h>
2223

2324

2425
using namespace emscripten;
2526
using namespace internal;
2627
using namespace facebook;
2728

29+
std::string CPPJS_DATA_PATH = "";
30+
2831
namespace emscripten {
2932
facebook::jsi::Runtime* jsRuntime = nullptr;
3033
namespace internal {
@@ -907,7 +910,9 @@ namespace emscripten {
907910
};
908911

909912

910-
EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings(jsi::Runtime& rt) {
913+
EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings(jsi::Runtime& rt, std::string path) {
914+
CPPJS_DATA_PATH = path;
915+
CppJS::setEnv("CPPJS_DATA_PATH", path, false);
911916
jsRuntime = &rt;
912917

913918
char* name = "M";
@@ -1006,6 +1011,15 @@ template <typename T> static void register_memory_view(const char* name) {
10061011
}
10071012
} // namespace
10081013

1014+
int CppJS::setEnv(std::string key, std::string value, bool overwrite) {
1015+
return setenv(key.c_str(), value.c_str(), overwrite);
1016+
}
1017+
std::string CppJS::getEnv(std::string key) {
1018+
char* value = getenv(key.c_str());
1019+
std::string valueStr = std::string(value);
1020+
// free(value);
1021+
return valueStr;
1022+
}
10091023

10101024
EMSCRIPTEN_BINDINGS(builtin) {
10111025
using namespace emscripten::internal;
@@ -1070,11 +1084,17 @@ EMSCRIPTEN_BINDINGS(builtin) {
10701084
register_memory_view<double>("emscripten::memory_view<double>");
10711085

10721086
// register_vector<bool>("BoolVector");
1073-
register_vector<char>("CharVector");
1087+
/* register_vector<char>("CharVector");
10741088
register_vector<short>("ShortVector");
10751089
register_vector<int>("IntVector");
10761090
register_vector<int64_t>("Int64_tVector");
10771091
register_vector<float>("FloatVector");
10781092
register_vector<double>("DoubleVector");
1079-
register_vector<std::string>("StringVector");
1093+
register_vector<std::string>("StringVector"); */
1094+
1095+
class_<CppJS>("CppJS")
1096+
.class_function("setEnv", &CppJS::setEnv)
1097+
.class_function("getEnv", &CppJS::getEnv)
1098+
;
1099+
constant("CPPJS_DATA_PATH", CPPJS_DATA_PATH);
10801100
}

core/cppjs-core-rn-embind/cpp/src/emscripten/bind.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace emscripten {
4242
};
4343

4444
namespace internal {
45-
EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings(facebook::jsi::Runtime& rt);
45+
EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings(facebook::jsi::Runtime& rt, std::string path);
4646

4747
typedef int32_t GenericEnumValue;
4848

@@ -2668,6 +2668,10 @@ namespace internal {
26682668
v[index] = value;
26692669
return true;
26702670
}
2671+
2672+
static int size(VectorType& v) {
2673+
return (int) v.size();
2674+
}
26712675
};
26722676

26732677
} // end namespace internal
@@ -2678,12 +2682,12 @@ class_<std::vector<T>> register_vector(const char* name) {
26782682

26792683
void (VecType::*push_back)(const T&) = &VecType::push_back;
26802684
void (VecType::*resize)(const size_t, const T&) = &VecType::resize;
2681-
size_t (VecType::*size)() const = &VecType::size;
2685+
// size_t (VecType::*size)() const = &VecType::size;
26822686
return class_<std::vector<T>>(name)
26832687
.template constructor<>()
26842688
.function("push_back", push_back)
26852689
.function("resize", resize)
2686-
.function("size", size)
2690+
.function("size", &internal::VectorAccess<VecType, T>::size)
26872691
.function("get", &internal::VectorAccess<VecType, T>::get)
26882692
.function("set", &internal::VectorAccess<VecType, T>::set)
26892693
;
@@ -2823,3 +2827,9 @@ void constant(const char* name, const ConstantType& v) {
28232827
static void embind_init_##name()
28242828

28252829
} // end namespace emscripten
2830+
2831+
class CppJS {
2832+
public:
2833+
static int setEnv(std::string key, std::string value, bool overwrite);
2834+
static std::string getEnv(std::string key);
2835+
};

core/cppjs-core-rn-embind/js/embind.js

+27-7
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function readFromMemoryUsingBit(pointer, signed, bit) {
567567
default:
568568
throw new TypeError("Unknown bit");
569569
}
570-
570+
571571
return readFromMemoryUsingShift(pointer, signed, shift);
572572
}
573573

@@ -583,7 +583,7 @@ function readFromMemoryUsingSize(pointer, signed, bit) {
583583
default:
584584
throw new TypeError("Unknown size");
585585
}
586-
586+
587587
return readFromMemoryUsingShift(pointer, signed, shift);
588588
}
589589

@@ -1512,7 +1512,7 @@ function dbg(text) {
15121512
return readFromMemoryUsingShift(pointer, true, 2, true);
15131513
};
15141514
case 3:
1515-
case 3n:
1515+
case 3n:
15161516
return function(pointer) {
15171517
return readFromMemoryUsingShift(pointer, true, 3, true);
15181518
};
@@ -1552,7 +1552,7 @@ function dbg(text) {
15521552
function simpleReadValueFromPointer(pointer) {
15531553
/* console.log(
15541554
'simpleReadValueFromPointer :',
1555-
this.name, JSON.stringify(pointer, null, 2),
1555+
this.name, JSON.stringify(pointer, null, 2),
15561556
readFromMemoryUsingShift(pointer, true, 2)
15571557
); */
15581558
return this['fromWireType'](readFromMemoryUsingShift(pointer, true, 2));
@@ -1561,7 +1561,7 @@ function dbg(text) {
15611561
function simpleReadValueFromPointer64(pointer) {
15621562
/* console.log(
15631563
'simpleReadValueFromPointer :',
1564-
this.name, JSON.stringify(pointer, null, 3),
1564+
this.name, JSON.stringify(pointer, null, 3),
15651565
readFromMemoryUsingShift(pointer, true, 3)
15661566
); */
15671567
return this['fromWireType'](readFromMemoryUsingShift(pointer, false, 3));
@@ -1618,7 +1618,7 @@ function dbg(text) {
16181618
}
16191619
function stringToUTF8(str, outPtr, maxBytesToWrite) {
16201620
assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
1621-
1621+
16221622
const index = getHeapIndex(outPtr);
16231623
return stringToUTF8Array(str, HEAPU8[index], outPtr - HEAP_OFFSET[index], maxBytesToWrite);
16241624
}
@@ -1768,7 +1768,7 @@ function dbg(text) {
17681768
/* if (!usePointer) {
17691769
return value;
17701770
}
1771-
1771+
17721772
if (value instanceof ArrayBuffer) {
17731773
value = new Uint8Array(value)
17741774
}
@@ -4746,3 +4746,23 @@ run();
47464746

47474747
globalThis.Module['ASSERTIONS'] = true;
47484748
export default globalThis.Module;
4749+
4750+
function toArray(vector) {
4751+
console.log('aaaaa', vector);
4752+
const output = [];
4753+
for (let i = 0; i < vector.size(); i += 1) {
4754+
output.push(vector.get(i));
4755+
}
4756+
return output;
4757+
}
4758+
4759+
function toVector(VectorClass, array = []) {
4760+
const vector = new VectorClass();
4761+
array.forEach((item) => {
4762+
vector.push_back(item);
4763+
});
4764+
return vector;
4765+
}
4766+
4767+
globalThis.Module.toArray = toArray;
4768+
globalThis.Module.toVector = toVector;

core/cppjs-core-rn-embind/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
{
33
"name": "cppjs-core-rn-embind",
4-
"version": "0.3.0",
4+
"version": "1.0.0-alpha.2",
55
"description": "IOS embind implementation for React Native",
66
"author": "Bugra Sari",
77
"homepage": "https://github.com/bugra9/cpp.js",
88
"license": "MIT",
99
"main": "js/embind.js",
1010
"peerDependencies": {
1111
"@babel/runtime": "^7.20.7",
12-
"react-native": "^0.72.0"
12+
"react-native": "^0.74.3"
1313
},
1414
"dependencies": {
1515
"cpp.js": "workspace:^"

core/cppjs-core-sample-creator/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-cpp.js",
3-
"version": "0.6.2",
3+
"version": "1.0.0-alpha.2",
44
"description": "",
55
"bin": "src/index.js",
66
"main": "src/index.js",

core/cppjs-core-sample-list/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "cppjs-samples",
3-
"version": "0.6.2",
3+
"version": "1.0.0-alpha.2",
44
"description": "Cpp.js Samples",
5-
"author": "Buğra Sarı <[email protected]>",
5+
"author": "Bugra SARI <[email protected]>",
66
"license": "MIT",
77
"type": "module",
88
"main": "index.js",

core/cppjs-core/package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
{
22
"name": "cpp.js",
3-
"version": "0.6.1",
3+
"version": "1.0.0-alpha.2",
44
"license": "MIT",
55
"type": "module",
6+
"homepage": "https://cpp.js.org",
7+
"repository": "https://github.com/bugra9/cpp.js.git",
68
"scripts": {
79
"test": "mocha"
810
},
911
"bin": {
1012
"cpp.js": "./src/bin.js"
1113
},
12-
"main": "/src/index.js",
14+
"main": "src/index.js",
1315
"dependencies": {
16+
"@rollup/plugin-commonjs": "^26.0.1",
17+
"@rollup/plugin-node-resolve": "^15.2.3",
18+
"@rollup/plugin-virtual": "^3.0.2",
1419
"commander": "^9.4.1",
15-
"glob": "^8.0.3"
20+
"glob": "^8.0.3",
21+
"rollup": "^4.18.0",
22+
"rollup-plugin-uglify": "^6.0.4"
1623
},
1724
"devDependencies": {
1825
"mocha": "^10.2.0"

core/cppjs-core/src/assets/CMakeLists.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ file(GLOB_RECURSE HEADER_FILES ${HEADER_GLOB})
4545
target_include_directories("${PROJECT_NAME}" PUBLIC "${HEADER_DIR}")
4646

4747
if (BUILD_SOURCE)
48-
target_sources("${PROJECT_NAME}"
49-
PUBLIC FILE_SET HEADERS
50-
BASE_DIRS "${HEADER_DIR}"
51-
FILES "${HEADER_FILES}")
52-
string(REPLACE "-" ";" HEADER_FOLDER ${PROJECT_NAME})
53-
list(GET HEADER_FOLDER 2 HEADER_FOLDER)
54-
install(TARGETS "${PROJECT_NAME}" DESTINATION "prebuilt/${PACKAGE_HOST}/lib")
55-
install(TARGETS "${PROJECT_NAME}" FILE_SET HEADERS DESTINATION "prebuilt/${PACKAGE_HOST}/include/cppjs-lib-${HEADER_FOLDER}")
48+
install(TARGETS "${PROJECT_NAME}" DESTINATION "lib")
49+
if(NOT "${HEADER_FILES}" STREQUAL "")
50+
target_sources("${PROJECT_NAME}"
51+
PUBLIC FILE_SET HEADERS
52+
BASE_DIRS "${HEADER_DIR}"
53+
FILES "${HEADER_FILES}")
54+
install(TARGETS "${PROJECT_NAME}" FILE_SET HEADERS DESTINATION "include")
55+
endif()
5656
endif(BUILD_SOURCE)
5757
unset(BUILD_SOURCE CACHE)
5858

0 commit comments

Comments
 (0)