From 1cee9136e0063c6ad378641b080cbd233079c9a9 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:42:37 -0300 Subject: [PATCH] Add Nix support to `compiler-wasm` (#22) * add nix target to compiler-wasm * fmt * fix test-build * fetch tags in test-build * fetch tags: take 2 --- .github/workflows/test-build.yaml | 14 +++++++++++--- compiler-wasm/src/lib.rs | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-build.yaml b/.github/workflows/test-build.yaml index bfe2ceb7e..132af5360 100644 --- a/.github/workflows/test-build.yaml +++ b/.github/workflows/test-build.yaml @@ -40,6 +40,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable @@ -62,7 +64,9 @@ jobs: - name: Build archive shell: bash run: | - VERSION="${GITHUB_REF#refs/tags/}" + # Get latest version + # https://stackoverflow.com/a/69708418 + VERSION="$(git describe --tags "$(git rev-list --tags --max-count=1)")" if [ "${{ matrix.os }}" = "windows-latest" ]; then ARCHIVE="glistix-$VERSION-${{ matrix.target }}.zip" @@ -105,12 +109,14 @@ jobs: retention-days: 3 build-test-wasm: - name: build-release-wasm + name: build-test-wasm runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 @@ -128,7 +134,9 @@ jobs: - name: Build wasm archive run: | - VERSION="${GITHUB_REF#refs/tags/}" + # Get latest version + # https://stackoverflow.com/a/69708418 + VERSION="$(git describe --tags "$(git rev-list --tags --max-count=1)")" ARCHIVE="glistix-$VERSION-browser.tar.gz" tar -C compiler-wasm/pkg/ -czvf $ARCHIVE . diff --git a/compiler-wasm/src/lib.rs b/compiler-wasm/src/lib.rs index 6702f2d1f..f8a527181 100644 --- a/compiler-wasm/src/lib.rs +++ b/compiler-wasm/src/lib.rs @@ -116,8 +116,10 @@ pub fn compile_package(project_id: usize, target: &str) -> Result<(), String> { let target = match target.to_lowercase().as_str() { "erl" | "erlang" => Target::Erlang, "js" | "javascript" => Target::JavaScript, + "nix" => Target::Nix, _ => { - let msg = format!("Unknown target `{target}`, expected `erlang` or `javascript`"); + let msg = + format!("Unknown target `{target}`, expected `erlang`, `javascript` or `nix`"); return Err(msg); } }; @@ -150,6 +152,17 @@ pub fn read_compiled_erlang(project_id: usize, module_name: &str) -> Option Option { + let fs = get_filesystem(project_id); + let path = format!("/build/{}.nix", module_name); + fs.read(&Utf8PathBuf::from(path)).ok() +} + /// Clear any stored warnings. This is performed automatically when before compilation. /// #[wasm_bindgen]