Skip to content

Commit

Permalink
feat: add kcl version api for the wasm host (#1656)
Browse files Browse the repository at this point in the history
* feat: add kcl version api for the wasm host

Signed-off-by: peefy <[email protected]>

* ci: bump CI condition to pr on main and push on main

Signed-off-by: peefy <[email protected]>

---------

Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Sep 18, 2024
1 parent 79d047f commit f8f4247
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 23 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build-test-centos7-amd64.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Build and Test on centos7 amd64

on: ["push", "pull_request"]

on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test-centos7:
name: Build and Test on centos7 amd64
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/build-test-macos-arm64.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Build and Test on MacOS ARCH64
on: ["push", "pull_request"]
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/macos
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/build-test-ubuntu-arm64.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Build and Test on Linux ARCH64

on: ["push", "pull_request"]

on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test-arm64:
name: Build and Test on Linux ARM64
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/macos_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: build-and-test-macos
on: ["push", "pull_request"]
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/macos
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/mingw_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: build-and-test-windows-mingw
on: ["push", "pull_request"]
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test:
name: build and test on windows mingw
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ubuntu_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: build-and-test-ubuntu
on: ["push", "pull_request"]
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/linux
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/wasm_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: build-and-test-wasm
on: ["push", "pull_request"]
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/linux
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/windows_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: build-and-test-windows
on: ["push", "pull_request"]
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-test:
name: build and test on windows
Expand Down
28 changes: 17 additions & 11 deletions kclvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ pub unsafe extern "C" fn kcl_fmt(src_ptr: *const c_char) -> *const c_char {
}
}

fn intern_fmt(src: &str) -> Result<String, String> {
let api = API::default();
let args = &FormatCodeArgs {
source: src.to_string(),
};
match api.format_code(args) {
Ok(result) => String::from_utf8(result.formatted).map_err(|err| err.to_string()),
Err(err) => Err(err.to_string()),
}
}

/// Exposes a normal kcl version function to the WASM host.
#[no_mangle]
pub unsafe extern "C" fn kcl_version() -> *const c_char {
CString::new(kclvm_version::VERSION).unwrap().into_raw()
}

/// Exposes a normal kcl runtime error function to the WASM host.
#[no_mangle]
pub unsafe extern "C" fn kcl_runtime_err(buffer: *mut u8, length: usize) -> isize {
Expand All @@ -178,17 +195,6 @@ pub unsafe extern "C" fn kcl_runtime_err(buffer: *mut u8, length: usize) -> isiz
})
}

fn intern_fmt(src: &str) -> Result<String, String> {
let api = API::default();
let args = &FormatCodeArgs {
source: src.to_string(),
};
match api.format_code(args) {
Ok(result) => String::from_utf8(result.formatted).map_err(|err| err.to_string()),
Err(err) => Err(err.to_string()),
}
}

/// Exposes an allocation function to the WASM host.
///
/// _This implementation is copied from wasm-bindgen_
Expand Down

0 comments on commit f8f4247

Please sign in to comment.