Javascript Wrapper¶
Pre-Compiled Binaries¶
Download the precompiled binaries from Javascript, or the development versions from the buildbot server at Javascript. Remember to get both files,
coolprop.js
andcoolprop.wasm
.You can load your js file into your website, following the structure of the example here, which is also included at the above download.
Alternatively, you can link to our server directly to make sure that you always have the latest version of CoolProp. To do so, include the address
<script src="http://www.coolprop.sourceforge.net/jscript/coolprop.js"></script>
in your HTML header instead of the relative path<script src="coolprop.js"></script>
.A live demo of the Javascript library in action can also be found online.
Serving the JS¶
The .wasm file can cause some problems for hosting emscripten-compiled JS files. When locally hosting, you need to ensure that the .wasm file extension is served with MIME type application/wasm
. A simple webserver config in Python 3 for testing CoolProp (with proper hosting of the WASM) could read:
import http.server
from http.server import BaseHTTPRequestHandler, HTTPServer
port=8000
print("Running on port %d" % port)
http.server.SimpleHTTPRequestHandler.extensions_map['.wasm'] = 'application/wasm'
httpd = HTTPServer(('localhost', port), http.server.SimpleHTTPRequestHandler)
print("Mapping \".wasm\" to \"%s\"" %
http.server.SimpleHTTPRequestHandler.extensions_map['.wasm'])
httpd.serve_forever()
On Apache, you need to setup the server appropriately.
User-Compiled Binaries¶
Docker¶
We run the emscripten-based builds in a docker container and you can follow the CI example here, which is also the script that generates the official downloads.
Linux (deprecated)¶
We are following the instructions from emscripten.org - download the portable emscripten SDK emsdk for linux.
First download node.js, clang++ and llvm using:
sudo apt-get install nodejs clang++ llvm
Expand the SDK zip file linked above
At the console in the folder that contains the file emsdk run the commands:
emsdk update # This will fetch the list of things to download emsdk install latest # This will download and install the full toolchain
Go enjoy a nice walk or a cup of coffee - it will be a while
Activate the SDK just compiled:
emsdk activate latest # This will make the file ~/.emscripten with the paths to most of the binaries compiled in SDK
Modify the file
~/.emscripten
to make NODE_JS path equal towhich nodejs
if it doesn’t alreadyMake an environmental variable (in ~/.profile)
export EMSCRIPTEN=/path/to/emsdk
that points to the folder that containsemc++
,emcc
, etc.Check out coolprop:
git clone https://github.com/CoolProp/CoolProp --recursive
Folder creating:
mkdir -p build && cd build
Build the Javascript module:
cmake .. -DCOOLPROP_JAVASCRIPT_MODULE=ON -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake
Windows (deprecated)¶
Download the EMSDK installer, run the web download installer, that will install everything, and get you ready.
In the
%HOME%/.emscripten
file, make sure that there is only one entry for NODE_JS and it points to the right place. Mine looks like:import os SPIDERMONKEY_ENGINE = '' LLVM_ROOT='C:/Program Files/Emscripten/clang/e1.21.0_64bit' NODE_JS='C:/Program Files/Emscripten/node/0.10.17_64bit/node.exe' PYTHON='C:/Program Files/Emscripten/python/2.7.5.3_64bit/python.exe' EMSDK_GIT='C:/Program Files/Emscripten/git/1.8.3' EMSCRIPTEN_ROOT='C:/Program Files/Emscripten/emscripten/1.21.0' V8_ENGINE = '' TEMP_DIR = 'c:/users/belli/appdata/local/temp' COMPILER_ENGINE = NODE_JS JS_ENGINES = [NODE_JS]
Open an Emscripten command Prompt (Start->Emscripten->Emscripten command Prompt)
Make an environmental variable
EMSCRIPTEN
that points to the folder that containsemc++
,emcc
, etc.Navigate to the root of the source
Build the build folder:
mkdir build && cd build
Build the Javascript module:
cmake ../.. -DCOOLPROP_JAVASCRIPT_MODULE=ON -DCMAKE_TOOLCHAIN_FILE=%EMSCRIPTEN%/cmake/Modules/Platform/Emscripten.cmake