Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 3.03 KB

02.4.setup.javascript.md

File metadata and controls

59 lines (46 loc) · 3.03 KB

Installation & Setup: Javascript

  1. Install the necessary prerequesites for Dahlia.
  2. Install the Emscripten compiler toolchain
    1. For more details, see the HVCC Javascript - Getting Started documentation and Mozilla's Compiling a New C/C++ Module to WebAssembly documentation.
  3. Initialize the Emscripten compiler and configure the environment variables:
# If using Git Bash for Windows, first add 'alias python3=python' to bash aliases
# Don't use the *.bat Windows files as Dahlia isn't configured to run things in cmd
$ ./lib/emsdk/emsdk install latest
$ ./lib/emsdk/emsdk activate latest

# run once per terminal session (automatically handled by 'dahlia.sh')
$ source ./lib/emsdk/emsdk_env.sh

# output should give no warnings and look as below
$ emcc --check
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) <version>
shared:INFO: (Emscripten: Running sanity checks)
  1. If there's no errors from the above, then everything Dahlia needs for Javascript is ready to go. As a test, return to the dahlia root directory and generate for Javascript using HVCC:
# generate for a target (e.g. Javascript/WebAudio) from pd source using HVCC only
$ source ./dahlia.sh js
  1. If HVCC returns Error c2js: [WinError 193] %1 is not a valid Win32 application, there may be an issue with your Python environment or path configuration... or there may not. A (not ideal, possibly terrible) hotfix it is to open the Python script c2js.py located in dahlia/.venv/Lib/site-packages/hvcc/generators/c2js/. Find the three instances where subprocess.check_output() is called in that script, and append shell=True as a second argument to all of those calls. Example:
# First instance, around Line 101 in HVCC v0.9
subprocess.check_output(cmd, shell=True)

# Second instance, around Line 108 in HVCC v0.9
subprocess.check_output(cmd, shell=True)

# First instance, around Line 140 in HVCC v0.9
subprocess.check_output(  # WASM
    cmd + [  # type: ignore
        "-s", "WASM=1",
        "-s", f"EXPORT_NAME='{output_name}_Module'",
        "-o", wasm_js_path
    ], shell=True)
  1. Run source ./dahlia.sh js again and see if that fixes the issue. If it does, and you suspect the error is due to a bad Python path configuration, it may be possible to identify by adding a traceback call in an except block following the first call to subprocess.check_output(), as follows:
# First call to 'subprocess.check_output()', around Line 101 in HVCC v0.9
try:
    subprocess.check_output(cmd)  # run emscripten
except Exception:
    print(traceback.format_exc())
    return

NB: This is tracked by the following Dahlia issue: Javascript/WebAudio generation requires editing HVCC python source #15