This project is designed to include all "common" code, which are pure javascript that can run in both Node.js and browsers.
### Requirements
Node.js v12+ (recommended v14+)
### Build
Use following command in folder `<ORT_ROOT>/js/common` to install NPM packages, build typescript files and generate bundles:
```
npm ci
```
### Distribution
It should be able to consumed by both from projects that uses NPM packages (through a Node.js folder structure of `node_modules` folder that generated by `npm install onnxruntime-common`) and from a CDN service that serves a `.min.js` bundle file.
### Features
Following features are included in `onnxruntime-common`:
-`InferenceSession` interfaces
-`Tensor`/`OnnxValue` interfaces, implementation and a set of utility functions
-`Backend` interfaces and a set of functions for backend registration
## onnxruntime-node
> language: typescript/C++
> dependency: onnxruntime-common, ONNXRuntime.dll
> folder: <ORT_ROOT>/js/node
This project is designed to be used as a NPM package to enable Node.js users to consume ONNX Runtime via Node.js binding, in Node.js or any Node.js compatible environment.
### Requirements
Node.js v12+ (recommended v14+)
### Build
#### Build ONNX Runtime and Node.js binding
Follow [instructions](https://www.onnxruntime.ai/docs/how-to/build.html#apis-and-language-bindings) for building ONNX Runtime Node.js binding
#### Build Node.js binding only
Use following command in folder `<ORT_ROOT>/js/node` to install NPM packages and build typescript files:
```
npm ci
```
This will download the latest pre-built ONNX Runtime binaries for the current platform.
### Distribution
It should be able to consumed by from projects that uses NPM packages (through a Node.js folder structure of `node_modules` folder that generated by `npm install onnxruntime-node`).
2.~~Follow [instructions](https://www.onnxruntime.ai/docs/how-to/build.html#apis-and-language-bindings) for building ONNX Runtime WebAssembly. (TODO: document is not ready. we are working on it.)~~
It should be able to consumed by both from projects that uses NPM packages (through a Node.js folder structure of `node_modules` folder that generated by `npm install onnxruntime-web`) and from a CDN service that serves a `.min.js` file and one or multiple `.wasm` file(s).
1. Install NPM packages for ONNX Runtime common JavaScript library and required React Native JavaScript libraries
1. in `<ORT_ROOT>/js/`, run `npm ci`.
2. in `<ORT_ROOT>/js/common/`, run `npm ci`.
3. in `<ORT_ROOT>/js/react_native/`, run `yarn`.
2. Build Android ONNX Runtime package
1. Set up an Android build environment referring to [instruction](https://www.onnxruntime.ai/docs/how-to/build.html#android)
2. In `<ORT_ROOT>`, run this python script to build ONNX Runtime Android archive file. In windows, this requires admin account to build. If an app uses a fixed set of models, refer to [instruction](https://www.onnxruntime.ai/docs/how-to/build.html#android) and build a mobile version package
3. This generates `onnxruntime-mobile-<version>.aar` in `<BUILD_DIRECTORY>/aar_out/MinSizeRel/com/microsoft/onnxruntime/onnxruntime-mobile/<version>`. Copy `aar` file into `<ORT_ROOT>/js/react_native/android/libs` and rename it as `onnxruntime.aar`
4. To verify, open Android Emulator and run this command from `<ORT_ROOT>/js/react_native/android`
```sh
adb shell am instrument -w ai.onnxruntime.react_native.test/androidx.test.runner.AndroidJUnitRunner
```
3. Build iOS ONNX Runtime package
1. Set up iOS build environment referring to [instruction](https://www.onnxruntime.ai/docs/how-to/build.html#ios).
2. Build ONNX Runtime library for iOS from `<ORT_ROOT>` using this command,
Copy `<ORT_ROOT>/build/iOS/MinSizeRel/MinSizeRel-iphoneos/libonnxruntime.<version>.dylib` file into `<ORT_ROOT>/js/react_native/ios/Libraries/onnxruntime/lib/iphoneos`
3. Clean up the previous build and build ONNX Runtime library for iOS Simulator from `<ORT_ROOT>`
Copy `<ORT_ROOT>/build/iOS/MinSizeRel/MinSizeRel-iphonesimulator/libonnxruntime.<version>.dylib` file into `<ORT_ROOT>/js/react_native/ios/Libraries/onnxruntime/lib/iphonesimulator`
4. Edit `onnxruntime-react-native.iphoneos.podspec` and `onnxruntime-react-native.iphonesimulator.podsepc` in `<ORT_ROOT>/js/react_native` to change a version of ONNX Runtime library.
4. Update a version in `package.json` to align with ONNX Runtime version.
5. Test an example for Android and iOS. In Windows, open Android Emulator first. From `<ORT_ROOT>/js/react_native`
```sh
yarn bootstrap
yarn example ios
yarn example android
```
### NPM Packaging
1. Update a version using `npm verison <version>` from `<ORT_ROOT>/js/react_native` folder. If it's for a dev, use `npm version <version>-dev.<subversion>`
2. Run `yarn prepack` to change `onnxruntime-common` to point to a published npm package
3. Run `npm pack` and verify NPM package contents
4. Run `npm publish <tgz> --dry-run` to see how it's going to be published
5. Run `npm publish <tgz>` to publish to npmjs
### Distribution
It should be able to consumed by React Native projects that uses Yarn packages through `yarn add onnxruntime-react-native`.