Skip to content

Commit

Permalink
[wip] base setup for basis universal
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Oct 7, 2024
1 parent 66e4b34 commit edda5bf
Show file tree
Hide file tree
Showing 10 changed files with 1,255 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
cpp/basisu

# Android/IJ
#
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "externals/basis_universal"]
path = externals/basis_universal
url = https://github.com/BinomialLLC/basis_universal.git
3 changes: 3 additions & 0 deletions cpp/react-native-basis-universal.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "react-native-basis-universal.h"

using namespace basisu;

namespace facebook::react {

ReactNativeBasisUniversal::ReactNativeBasisUniversal(std::shared_ptr<CallInvoker> jsInvoker)
: NativeBasisUniversalCxxSpecJSI(jsInvoker), _callInvoker(jsInvoker) {}

double ReactNativeBasisUniversal::multiply(jsi::Runtime &rt, double a, double b) {
basist::basisu_transcoder_init();
return a * b;
}

Expand Down
1 change: 1 addition & 0 deletions cpp/react-native-basis-universal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <ReactCommon/TurboModule.h>
#include <RNBasisUniversalSpecJSI.h>
#include "basisu/transcoder/basisu_transcoder.h"

namespace facebook::react {

Expand Down
1 change: 1 addition & 0 deletions externals/basis_universal
Submodule basis_universal added at 6775d3
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"react-native-builder-bob": "^0.30.2",
"release-it": "^15.0.0",
"turbo": "^1.10.7",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"zx": "^8.1.9"
},
"resolutions": {
"@types/react": "^18.2.44"
Expand Down
8 changes: 8 additions & 0 deletions react-native-basis-universal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Pod::Spec.new do |s|

s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"

s.pod_target_xcconfig = {
'HEADER_SEARCH_PATHS' => '$(inherited) $(PODS_TARGET_SRCROOT)/cpp',
}


# TODO: Change to XCFramework
s.vendored_libraries = "externals/basis_universal/out/arm64_iphonesimulator/libbasisu_encoder.a"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
Expand Down
1,145 changes: 1,145 additions & 0 deletions scripts/apple.toolchain.cmake

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { $, cd } = require('zx');
const fs = require('fs');
const path = require('path');

const serializeCMakeArgs = (args: Record<string, string>) => {
return Object.keys(args)
.map((key) => `-D${key}=${args[key]}`)
.join(' ');
};

const CMAKE_ARGS = {
CMAKE_BUILD_TYPE: 'RELEASE',
// CMAKE_TOOLCHAIN_FILE: `${__dirname}/apple.toolchain.cmake`,
};

const PLATFORM_MAP: Record<string, string> = {
arm64_iphoneos: 'OS64',
arm64_iphonesimulator: 'SIMULATORARM64',
x86_64_iphonesimulator: 'SIMULATOR64',
};

const apple = {
arm64: ['iphonesimulator', 'iphoneos'],
x86_64: ['iphonesimulator'],
};

const buildStaticLibs = async (platform: string) => {
const baseDir = 'externals/basis_universal/out';
const dirPath = path.join(baseDir, platform);
fs.mkdirSync(dirPath, { recursive: true });
cd(`${__dirname}/../externals/basis_universal/out/${platform}`);
await $`cmake -S ../.. -G Ninja -DPLATFORM=${PLATFORM_MAP[platform]} ${serializeCMakeArgs(CMAKE_ARGS)} && ninja`;
};

const copyHeaders = async () => {
cd(`${__dirname}/..`);
fs.mkdirSync('cpp/basisu/encoder', { recursive: true });
fs.mkdirSync('cpp/basisu/transcoder', { recursive: true });
$`cp -r externals/basis_universal/encoder/*.h cpp/basisu/encoder`;
$`cp -r externals/basis_universal/transcoder/*.h cpp/basisu/transcoder`;
};

const main = () => {
for (const [arch, platforms] of Object.entries(apple)) {
for (const platform of platforms) {
const platformName = `${arch}_${platform}`;
buildStaticLibs(platformName);
}
}
copyHeaders();
};

main();
39 changes: 38 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,7 @@ __metadata:
release-it: ^15.0.0
turbo: ^1.10.7
typescript: ^5.2.2
zx: ^8.1.9
peerDependencies:
react: "*"
react-native: "*"
Expand Down Expand Up @@ -3168,6 +3169,16 @@ __metadata:
languageName: node
linkType: hard

"@types/fs-extra@npm:>=11":
version: 11.0.4
resolution: "@types/fs-extra@npm:11.0.4"
dependencies:
"@types/jsonfile": "*"
"@types/node": "*"
checksum: 242cb84157631f057f76495c8220707541882c00a00195b603d937fb55e471afecebcb089bab50233ed3a59c69fd68bf65c1f69dd7fafe2347e139cc15b9b0e5
languageName: node
linkType: hard

"@types/graceful-fs@npm:^4.1.3":
version: 4.1.9
resolution: "@types/graceful-fs@npm:4.1.9"
Expand Down Expand Up @@ -3226,6 +3237,15 @@ __metadata:
languageName: node
linkType: hard

"@types/jsonfile@npm:*":
version: 6.1.4
resolution: "@types/jsonfile@npm:6.1.4"
dependencies:
"@types/node": "*"
checksum: 309fda20eb5f1cf68f2df28931afdf189c5e7e6bec64ac783ce737bb98908d57f6f58757ad5da9be37b815645a6f914e2d4f3ac66c574b8fe1ba6616284d0e97
languageName: node
linkType: hard

"@types/minimist@npm:^1.2.0, @types/minimist@npm:^1.2.2":
version: 1.2.5
resolution: "@types/minimist@npm:1.2.5"
Expand All @@ -3242,7 +3262,7 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:*":
"@types/node@npm:*, @types/node@npm:>=20":
version: 22.7.4
resolution: "@types/node@npm:22.7.4"
dependencies:
Expand Down Expand Up @@ -13417,3 +13437,20 @@ __metadata:
checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700
languageName: node
linkType: hard

"zx@npm:^8.1.9":
version: 8.1.9
resolution: "zx@npm:8.1.9"
dependencies:
"@types/fs-extra": ">=11"
"@types/node": ">=20"
dependenciesMeta:
"@types/fs-extra":
optional: true
"@types/node":
optional: true
bin:
zx: build/cli.js
checksum: e094056cd6780d31b96d5b7179c0b3637823e0279bdb052a846a78c55fa0eaf2a9acb10bd4e5c4ff70281ac3ad440fd49f056203881710f66fff5a91ef41ba92
languageName: node
linkType: hard

0 comments on commit edda5bf

Please sign in to comment.