iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💍

Building Onyx from Source

に公開
2024/01/05

Conclusion

I was able to get it working as shown below after running git clone. At least in my environment.

source ./settings.sh && ONYX_RUNTIME_LIBRARY=ovmwasm ./build.sh compile install

Installing Onyx

https://zenn.dev/hatappo/articles/f1ecb49715ea6c

In the article above, I installed it using the installation script located at https://get.onyxlang.io [1].

Building Onyx from Source

In this article, I will build it from source. The procedure is listed at https://onyxlang.io/docs/install#source.

git clone https://github.com/onyx-lang/onyx
cd ./onyx
source settings.sh
./build.sh compile

It results in an error stating that the assembly file libwasmer.a is missing.

$ ./build.sh compile                             
Compiling onyx
clang: error: no such file or directory: '~/.wasmer/lib/libwasmer.a'

libwasmer.a seems to be a lightweight headless Wasmer compiler, but I don't know how to install it.

For now, reading build.sh suggests that the build branches between compiling with a compiler or an interpreter depending on the value of the ONYX_RUNTIME_LIBRARY environment variable.

./build.sh
compile_all() {
    if [ "$ONYX_RUNTIME_LIBRARY" = "ovmwasm" ]; then
        cd interpreter
        ./build.sh $1
        cd ..
    fi

    cd compiler
    ./build.sh $1
    cd ..

    if [ ! -z ${ONYX_RUNTIME_LIBRARY+x} ]; then
        cd runtime
        ./build.sh $1
        cd ..
    fi
}
./compiler/build.sh
    case "${ONYX_RUNTIME_LIBRARY}" in
        ovmwasm)
            LIBS="../shared/lib/$ONYX_ARCH/lib/libovmwasm.a $LIBS"
            FLAGS="$FLAGS -DUSE_OVM_DEBUGGER"
            ;;

        wasmer)
            LIBS="$(wasmer config --libdir)/libwasmer.a $LIBS"
            ;;

        # Used by MacOS ARM64 cross compilation
        wasmer-custom)
            LIBS="$WASMER_LIB_PATH/libwasmer.a $LIBS"
            ;;

        *)
            echo "Unknown WebAssembly runtime '$ONYX_RUNTIME_LIBRARY'. Aborting.";
            exit 1
            ;;
    esac

Building with ONYX_RUNTIME_LIBRARY="ovmwasm"[2] seems to eliminate the need for libwasmer.a. This setting is also mentioned as a comment in ./settings.sh, which is loaded during the build process.

$ ONYX_RUNTIME_LIBRARY=ovmwasm ./build.sh compile
Compiling ovmwasm to ../shared/lib/darwin_arm64/lib/libovmwasm.a
Compiling onyx
Compiling onyx_runtime.dylib

The binary is built in ./compiler/onyx.

$ ./compiler/onyx version                        
Onyx toolchain version v0.1.8
Built on Wed Jan  3 08:21:31 2024
Runtime: ovmwasm

Installation

$ ./build.sh install
Installing on 'Darwin ... (omitted) ... arm64'
Installing core libs
Installing core tools
Installing runtime library
Installing to $HOME/.onyx

Just add $HOME/.onyx/bin to your path as needed.

Build Time

Approximately 7 seconds.

$ time /bin/bash -c 'source ./settings.sh && ONYX_RUNTIME_LIBRARY=ovmwasm ./build.sh compile install'
# ... (omitted) ...
/bin/bash -c   6.53s user 0.95s system 85% cpu 8.712 total

Summary

Since I got an error due to the missing libwasmer.a, I tried building with ovmwasm, and it worked for now.

Hmm... I felt like I should study Wasmer itself more.

Other References

脚注
  1. This URL redirects to bin/install.sh in the dev branch of the https://github.com/onyx-lang/onyx repository. When I checked, there were no particular differences in this file between master and dev. ↩︎

  2. ovm stands for Onyx Virtual Machine, which I assume is Onyx's own runtime system, different from Wasm or Wasmer. ovm is slightly slower than Wasmer but supports debug execution. ↩︎

Discussion