@crossbind/example-lib-prebuilt-matrix 2.0.0-beta.50

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.
Files changed (50) hide show
  1. package/AGENTS.md +78 -0
  2. package/CHANGELOG.md +20 -0
  3. package/LICENSE +21 -0
  4. package/README.md +81 -0
  5. package/crossbind-example-lib-prebuilt-matrix.podspec +21 -0
  6. package/crossbind-example-lib-prebuilt-matrix.xcframework/Info.plist +47 -0
  7. package/crossbind-example-lib-prebuilt-matrix.xcframework/ios-arm64/Headers/Matrix.h +12 -0
  8. package/crossbind-example-lib-prebuilt-matrix.xcframework/ios-arm64/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  9. package/crossbind-example-lib-prebuilt-matrix.xcframework/ios-arm64-simulator/Headers/Matrix.h +12 -0
  10. package/crossbind-example-lib-prebuilt-matrix.xcframework/ios-arm64-simulator/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  11. package/crossbind.config.js +14 -0
  12. package/dist/crossbind-example-lib-prebuilt-matrix-wasi-wasm32-st-release.wasm +0 -0
  13. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-mt-release.browser.js +1363 -0
  14. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-mt-release.browser.wasm +0 -0
  15. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-mt-release.node.js +508 -0
  16. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-mt-release.node.wasm +0 -0
  17. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-st-release.browser.js +1363 -0
  18. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-st-release.browser.wasm +0 -0
  19. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-st-release.edge.js +478 -0
  20. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-st-release.edge.wasm +0 -0
  21. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-st-release.node.js +508 -0
  22. package/dist/crossbind-example-lib-prebuilt-matrix-wasm-wasm32-st-release.node.wasm +0 -0
  23. package/dist/prebuilt/CMakeLists.txt +57 -0
  24. package/dist/prebuilt/android-arm64-v8a-mt-release/crossbind-emccflags.fingerprint +1 -0
  25. package/dist/prebuilt/android-arm64-v8a-mt-release/include/Matrix.h +12 -0
  26. package/dist/prebuilt/android-arm64-v8a-mt-release/lib/libcrossbind-example-lib-prebuilt-matrix.so +0 -0
  27. package/dist/prebuilt/android-x86_64-mt-release/crossbind-emccflags.fingerprint +1 -0
  28. package/dist/prebuilt/android-x86_64-mt-release/include/Matrix.h +12 -0
  29. package/dist/prebuilt/android-x86_64-mt-release/lib/libcrossbind-example-lib-prebuilt-matrix.so +0 -0
  30. package/dist/prebuilt/ios-iphoneos-mt-release/crossbind-emccflags.fingerprint +1 -0
  31. package/dist/prebuilt/ios-iphoneos-mt-release/include/Matrix.h +12 -0
  32. package/dist/prebuilt/ios-iphoneos-mt-release/lib/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  33. package/dist/prebuilt/ios-iphonesimulator-mt-release/crossbind-emccflags.fingerprint +1 -0
  34. package/dist/prebuilt/ios-iphonesimulator-mt-release/include/Matrix.h +12 -0
  35. package/dist/prebuilt/ios-iphonesimulator-mt-release/lib/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  36. package/dist/prebuilt/wasi-wasm32-st-release/crossbind-emccflags.fingerprint +1 -0
  37. package/dist/prebuilt/wasi-wasm32-st-release/include/Matrix.h +12 -0
  38. package/dist/prebuilt/wasi-wasm32-st-release/lib/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  39. package/dist/prebuilt/wasm-wasm32-mt-release/crossbind-emccflags.fingerprint +1 -0
  40. package/dist/prebuilt/wasm-wasm32-mt-release/include/Matrix.h +12 -0
  41. package/dist/prebuilt/wasm-wasm32-mt-release/lib/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  42. package/dist/prebuilt/wasm-wasm32-st-release/crossbind-emccflags.fingerprint +1 -0
  43. package/dist/prebuilt/wasm-wasm32-st-release/include/Matrix.h +12 -0
  44. package/dist/prebuilt/wasm-wasm32-st-release/lib/libcrossbind-example-lib-prebuilt-matrix.a +0 -0
  45. package/dist/types/index.d.ts +9 -0
  46. package/package.json +38 -0
  47. package/playground/Matrix.js +19 -0
  48. package/playground/index.html +74 -0
  49. package/src/native/Matrix.cpp +17 -0
  50. package/src/native/Matrix.h +12 -0
@@ -0,0 +1,57 @@
1
+ set(MY_LIST "android-arm64-v8a-mt-release;android-x86_64-mt-release;ios-iphoneos-mt-release;ios-iphonesimulator-mt-release;wasi-wasm32-st-release;wasm-wasm32-mt-release;wasm-wasm32-st-release")
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}")
5
+ endif()
6
+ LIST(FIND MY_LIST "${PROJECT_TARGET_HOST}" PACKAGE_HOST_INDEX)
7
+
8
+ if(NOT PACKAGE_HOST_INDEX EQUAL -1)
9
+ cmake_minimum_required(VERSION 3.28)
10
+ set(CMAKE_CXX_STANDARD 11)
11
+ set(PROJECT_NAME "crossbind-example-lib-prebuilt-matrix")
12
+ set(PROJECT_LIBS "crossbind-example-lib-prebuilt-matrix")
13
+ project("${PROJECT_NAME}")
14
+
15
+ if (APPLE AND CMAKE_SYSTEM_NAME STREQUAL "iOS")
16
+ set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/../..")
17
+ else()
18
+ set(PACKAGE_DIR "${PROJECT_SOURCE_DIR}/${PROJECT_TARGET_HOST}/lib")
19
+ endif()
20
+
21
+ set(PROJECT_LIBS_DIR)
22
+ foreach(L IN LISTS PROJECT_LIBS)
23
+ SET(FOUND_LIB "FOUND_LIB-NOTFOUND")
24
+ find_library(FOUND_LIB
25
+ NAMES "${L}"
26
+ PATHS "${PACKAGE_DIR}"
27
+ NO_CACHE
28
+ NO_DEFAULT_PATH
29
+ NO_CMAKE_FIND_ROOT_PATH
30
+ REQUIRED
31
+ )
32
+ LIST(APPEND PROJECT_LIBS_DIR ${FOUND_LIB})
33
+ endforeach()
34
+
35
+ add_library("${PROJECT_NAME}" INTERFACE)
36
+ # Cargo producers register through an init-array constructor nothing references. KEEP pins the
37
+ # generated keep symbol (--undefined) so only the registration object is pulled - never the
38
+ # whole archive, because each Rust staticlib bundles libstd and fully loading two of them
39
+ # duplicates thousands of std symbols. FORCE (manual-bindings crates, no keep symbol) falls
40
+ # back to whole-archive - safe only as the app's single loaded Rust archive. (Apple consumers
41
+ # get the equivalent flags from the generated podspec instead.)
42
+ set(PROJECT_RUST_LINK "")
43
+ if(PROJECT_RUST_LINK STREQUAL "KEEP" AND NOT APPLE)
44
+ target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_LIBS_DIR}")
45
+ foreach(L IN LISTS PROJECT_LIBS)
46
+ target_link_options("${PROJECT_NAME}" INTERFACE "-Wl,--undefined=crossbind_keep_${L}")
47
+ endforeach()
48
+ elseif(PROJECT_RUST_LINK STREQUAL "FORCE" AND NOT APPLE)
49
+ target_link_libraries("${PROJECT_NAME}" INTERFACE "$<LINK_LIBRARY:WHOLE_ARCHIVE,${PROJECT_LIBS_DIR}>")
50
+ else()
51
+ target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_LIBS_DIR}")
52
+ endif()
53
+
54
+ if(NOT APPLE)
55
+ target_include_directories("${PROJECT_NAME}" INTERFACE "${PROJECT_SOURCE_DIR}/${PROJECT_TARGET_HOST}/include")
56
+ endif()
57
+ endif()
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1 @@
1
+ 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };
@@ -0,0 +1,9 @@
1
+ // Generated by crossbind - do not edit. Values are usable after init().
2
+
3
+ export declare class Matrix {
4
+ constructor(size: number, initValue: number);
5
+ get(i: number): number;
6
+ multiple(b: Matrix): Matrix | null;
7
+ }
8
+ export declare let AllSymbols: Record<string, unknown>;
9
+ export declare function initNative(config?: Record<string, unknown>): Promise<unknown>;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@crossbind/example-lib-prebuilt-matrix",
3
+ "version": "2.0.0-beta.50",
4
+ "description": "crossbind sample prebuilt library: matrix multiplier",
5
+ "homepage": "https://github.com/crossbind/crossbind/tree/main/examples/lib-prebuilt-matrix#readme",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/crossbind/crossbind.git"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "devDependencies": {
13
+ "crossbind": "^2.0.0-beta.50"
14
+ },
15
+ "keywords": [
16
+ "crossbind-sample",
17
+ "matrix",
18
+ "crossbind-sample",
19
+ "webassembly",
20
+ "react-native"
21
+ ],
22
+ "types": "./dist/types/index.d.ts",
23
+ "typesVersions": {
24
+ "*": {
25
+ "*.h": [
26
+ "./dist/types/index.d.ts"
27
+ ]
28
+ }
29
+ },
30
+ "scripts": {
31
+ "build": "crossbind build",
32
+ "builda": "crossbind build -p wasm -p android",
33
+ "build:wasm": "crossbind build -p wasm",
34
+ "build:android": "crossbind build -p android",
35
+ "build:ios": "crossbind build -p ios",
36
+ "clear": "rm -rf .crossbind dist *.xcframework"
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ class Matrix extends Array {
2
+ constructor(size, initValue) { super(size); this.fill(initValue); }
3
+
4
+ get(i) { return this[i]; }
5
+
6
+ multiple(otherMatrix) {
7
+ const size = Math.sqrt(this.length);
8
+ const result = new Matrix(this.length, 0);
9
+
10
+ for (let i = 0; i < size; i += 1) {
11
+ for (let j = 0; j < size; j += 1) {
12
+ for (let k = 0; k < size; k += 1) {
13
+ result[i * size + j] += this[i * size + k] * otherMatrix[k * size + j];
14
+ }
15
+ }
16
+ }
17
+ return result;
18
+ }
19
+ }
@@ -0,0 +1,74 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset = "utf-8">
6
+ <title>C++ Matrix Multiplier</title>
7
+ <script src="./Matrix.js"></script>
8
+ <script type="module">
9
+ import '../dist/crossbind-example-lib-prebuilt-matrix.browser.js';
10
+ let wasmModule;
11
+ initNative();
12
+ const SIZE = Math.pow(1100, 2);
13
+
14
+
15
+ async function init () {
16
+ wasmModule = await initNative({ path: '../dist' });
17
+ new wasmModule.Matrix(10, 0);
18
+ toggleVisible(true);
19
+ }
20
+
21
+ function runCore(type) {
22
+ const MatrixClass = type === 'wasm' ? wasmModule.Matrix : Matrix;
23
+ const a = new MatrixClass(SIZE, 1);
24
+ const b = new MatrixClass(SIZE, 2);
25
+
26
+ const startTime = new Date();
27
+ const result = a.multiple(b);
28
+
29
+ writeResult(type, result.get(0), ((new Date()) - startTime) / 1000);
30
+ }
31
+ function run(type) {
32
+ toggleVisible(false);
33
+ setTimeout(() => runCore(type), 200);
34
+ setTimeout(() => toggleVisible(true), 200);
35
+ }
36
+ function writeResult(type, result, duration) {
37
+ document.querySelector(`#${type}-result`).innerHTML = result;
38
+ document.querySelector(`#${type}-duration`).innerHTML = duration;
39
+ }
40
+ function toggleVisible(visible) {
41
+ document.querySelector('#loading').style.display = visible ? "none" : "block";
42
+ document.querySelector('main').style.display = visible ? "block" : "none";
43
+ }
44
+ window.run = run;
45
+ </script>
46
+ <style>
47
+ body {
48
+ padding: 50px;
49
+ }
50
+ table, th, td {
51
+ border: 1px solid red;
52
+ border-collapse: collapse;
53
+ }
54
+ table {
55
+ width: 400px;
56
+ margin-top: 20px;
57
+ }
58
+ </style>
59
+ </head>
60
+ <body>
61
+ <div id="loading">Loading ...</div>
62
+ <main style="display: none;">
63
+ <div>
64
+ <button type="button" onclick="run('js')">Calculate using JS</button>
65
+ <button type="button" onclick="run('wasm')">Calculate using WASM</button>
66
+ </div>
67
+ <table>
68
+ <tr><td>Type</td><td>result[0]</td><td>Duration (s)</td></tr>
69
+ <tr><td>JS</td><td id="js-result"></td><td id="js-duration"></td></tr>
70
+ <tr><td>WASM</td><td id="wasm-result"></td><td id="wasm-duration"></td></tr>
71
+ </table>
72
+ </main>
73
+ </body>
74
+ </html>
@@ -0,0 +1,17 @@
1
+ #include "Matrix.h"
2
+
3
+ int Matrix::get(int i) { return this->at(i); }
4
+
5
+ std::shared_ptr<Matrix> Matrix::multiple(std::shared_ptr<Matrix> b) {
6
+ int size = sqrt(this->size());
7
+ auto result = std::make_shared<Matrix>(this->size(), 0);
8
+
9
+ for (int i = 0; i < size; i += 1) {
10
+ for (int j = 0; j < size; j += 1) {
11
+ for (int k = 0; k < size; k += 1) {
12
+ (*result)[i * size + j] += this->at(i * size + k) * (*b)[k * size + j];
13
+ }
14
+ }
15
+ }
16
+ return result;
17
+ }
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ #include <vector>
4
+ #include <memory>
5
+ #include <cmath>
6
+
7
+ class Matrix : public std::vector<int> {
8
+ public:
9
+ Matrix(int size, int initValue) : std::vector<int>(size, initValue) {}
10
+ int get(int i);
11
+ std::shared_ptr<Matrix> multiple(std::shared_ptr<Matrix> b);
12
+ };