Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add kcl version api for the wasm host #1656

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading