Skip to content

Commit

Permalink
Add Nix support to compiler-wasm (#22)
Browse files Browse the repository at this point in the history
* add nix target to compiler-wasm

* fmt

* fix test-build

* fetch tags in test-build

* fetch tags: take 2
  • Loading branch information
PgBiel authored Sep 30, 2024
1 parent b629710 commit 1cee913
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 .
Expand Down
15 changes: 14 additions & 1 deletion compiler-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -150,6 +152,17 @@ pub fn read_compiled_erlang(project_id: usize, module_name: &str) -> Option<Stri
fs.read(&Utf8PathBuf::from(path)).ok()
}

/// Get the compiled Nix output for a given module.
///
/// You need to call `compile_package` before calling this function.
///
#[wasm_bindgen]
pub fn read_compiled_nix(project_id: usize, module_name: &str) -> Option<String> {
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]
Expand Down

0 comments on commit 1cee913

Please sign in to comment.