Skip to content

Latest commit

 

History

History
123 lines (78 loc) · 5.55 KB

RHINO3DM-BUILD.JS.md

File metadata and controls

123 lines (78 loc) · 5.55 KB

rhino3dm.js build instructions

Get the Source

If the pre-compiled libraries do not work in your situation, you can compile the libraries from their source, the repo uses OpenNURBS as a submodule, so you need to run a couple more git commands after you have cloned. cd into the new repository directory and run

git submodule update --init

Required Tools

Compiling rhino3dm.js can be done on macOS, Linux and Windows (via Windows Subsystem for Linux). The following tools are required...

⭐️ TIP: A great way to get a build environment that's ready to go for building rhino3dm.js is to use a Dev Container in VS Code! 🐳

Scripts

A number of scripts are used to setup and build rhino3dm:

  • script/bootstrap.py - checks for (and downloads) the required tools
  • script/setup.py - generates the platform-specific project files using CMake
  • script/build.py - builds the library project(s)

These scripts support Python 2 and 3 on Windows (linux subsystem), macOS, or Linux (Ubuntu).

Running scripts on Windows

You have to make sure that the Emscripten environment is set up. Here are the steps to install Emscripten and the make tool to make it work. After that you can set up the environment by running emsdk_env.bat.

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
emsdk install latest
emsdk activate latest
emsdk install mingw-4.6.2-32bit
emsdk activate mingw-4.6.2-32bit

bootstrap.py

The script/bootstrap.py script can be used to check your system for (and, in some cases, download) the necessary tools for a specific build target. For example, you can run:

$ python3 bootstrap.py --platform js

to check for all the tools needed to build the javascript version of rhino3dm.

setup.py

The setup.py script uses CMake to generate the make files necessary to build the project. These projects are generated into build/javascript folder. To setup a JavaScript build, you can run:

$ python3 setup.py --platform js --verbose

build.py

The build.py script run make to build the rhino3dm.js and rhino3dm.wasm files to the build/javascript/artifacts_js folder. To build, run:

$ python3 build.py --platform js --verbose --overwrite

The build might take a few minutes, but if everything is configured correctly you should now have rhino3dm.js and rhino3dm.wasm in the build/javascript/artifacts_js folder. The script also copies these files to the docs/javascript/samples/resources folder where they can be used for testing.

Test

  • cd to the docs/javascript/samples folder.

  • Type python3 -m http.server. This will run a simple web server which serves files in the artifacts directory

  • Go to your browser and navigate to http://localhost:8080/rhino3dm.html

  • For chrome, right click and select inspect. Click on the console tab and try typing in the following javascript:

> sphere = new _rhino3dm.Sphere([1,2,3], 12);
> brep = sphere.toBrep();
> jsonobject = brep.encode();

Dev Container

Getting the toolchain set up for building rhino3dm.js can be painful. Visual Studio Code can help by using a preconfigured Docker container as a development environment.

macos setup

  1. Install vscode: https://code.visualstudio.com/

  2. Install Docker desktop: https://docs.docker.com/get-docker/ and start the docker app

  3. Install vscode extension for containers: https://code.visualstudio.com/docs/containers/overview

  4. Open the rhino3dm directory in vscode and open a terminal.

  5. In the terminal, run the following command:

    docker run --rm -dit -v $(pwd):/src emscripten/emsdk:3.1.30

    --rm deletes the container when it's stopped

    -dit runs the container as a daemon (in the background) but still allows interaction

    -v $(pwd):/src maps the current directory (rhino3dm) to /src in the container. On Windows you should include the full path to the rhino3dm directory. For example:

    docker run --rm -dit -v c:\dev\rhino3dm:/src emscripten/emsdk:3.1.30

    emsdk:3.1.30 is the version of emscripten we are using.

  6. In vs code, open Docker explorer

  7. You should see a container in the list. Right-click on it and select "Attach shell" which will open a new terminal from the container. Alternatively, you can run docker exec -it <mycontainer> bash, where <mycontainer> is the container id printed out after step 5.

  8. Make sure the terminal is in the rhino3dm directory. Run the following command to setup the rhino3dm.js build:

    python3 script/setup.py --platform js

  9. Run the following command to build rhino3dm.js (use --verbose to get verbose output while compiling):

    python3 script/build.py --platform js --overwrite --verbose

Related Topics

  • Current Development Tools - This file (which is used by bootstrap) lists the current build tools and versions we have tested with.