Skip to content

Commit

Permalink
ci: add wasm target unit test and release (kcl-lang#1380)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored May 30, 2024
1 parent e824bd6 commit 2519191
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/wasm_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: build-and-test-wasm
on: ["push", "pull_request"]
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/linux
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
submodules: "true"

- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.76
override: true
components: clippy, rustfmt

- name: Unit test
working-directory: ./kclvm
run: rustup target add wasm32-wasi && make build-wasm
shell: bash

- uses: actions/upload-artifact@v3
with:
name: kcl-wasm
path: kclvm/target/wasm32-wasi/release/kclvm_cli_cdylib.wasm
2 changes: 2 additions & 0 deletions kclvm/api/src/service/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub(crate) fn kclvm_get_service_fn_ptr_by_name(name: &str) -> u64 {
"KclvmService.Rename" => rename as *const () as u64,
"KclvmService.RenameCode" => rename_code as *const () as u64,
"KclvmService.Test" => test as *const () as u64,
#[cfg(not(target_arch = "wasm32"))]
"KclvmService.UpdateDependencies" => update_dependencies as *const () as u64,
_ => panic!("unknown method name : {name}"),
}
Expand Down Expand Up @@ -524,6 +525,7 @@ pub(crate) fn test(
call!(serv, args, result_len, TestArgs, test)
}

#[cfg(not(target_arch = "wasm32"))]
/// Service for the dependencies updating
/// calling information.
///
Expand Down
6 changes: 4 additions & 2 deletions kclvm/api/src/service/service_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::string::String;

use crate::gpyrpc::*;
Expand All @@ -9,7 +9,6 @@ use anyhow::anyhow;
use kcl_language_server::rename;
use kclvm_config::settings::build_settings_pathbuf;
use kclvm_driver::canonicalize_input_files;
use kclvm_driver::client::ModClient;
use kclvm_loader::option::list_options;
use kclvm_loader::{load_packages_with_cache, LoadPackageOptions};
use kclvm_parser::load_program;
Expand Down Expand Up @@ -957,6 +956,7 @@ impl KclvmServiceImpl {
Ok(result)
}

#[cfg(not(target_arch = "wasm32"))]
/// update_dependencies provides users with the ability to update kcl module dependencies.
///
/// # Examples
Expand Down Expand Up @@ -986,6 +986,8 @@ impl KclvmServiceImpl {
&self,
args: &UpdateDependenciesArgs,
) -> anyhow::Result<UpdateDependenciesResult> {
use kclvm_driver::client::ModClient;
use std::path::Path;
let mut client = ModClient::new(&args.manifest_path)?;
if args.vendor {
client.set_vendor(&Path::new(&args.manifest_path).join("vendor"));
Expand Down
6 changes: 4 additions & 2 deletions kclvm/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ walkdir = "2"
serde = { version = "1.0", features = ["derive"] }
anyhow = { version = "1.0.70", features = ["backtrace"] }
glob = "0.3.1"
oci-distribution = { default-features = false, version = "0.11.0", features = ["rustls-tls"] }
flate2 = "1.0.30"
tar = "0.4.40"
tokio = { version = "1.37.0", features = ["full"] }
indexmap = "2.2.6"
once_cell = "1.19.0"
parking_lot = "0.12.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
oci-distribution = { default-features = false, version = "0.11.0", features = ["rustls-tls"] }
tokio = { version = "1.37.0", features = ["full"] }
1 change: 1 addition & 0 deletions kclvm/driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod arguments;
#[cfg(not(target_arch = "wasm32"))]
pub mod client;
pub mod toolchain;

Expand Down
7 changes: 4 additions & 3 deletions kclvm/driver/src/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::client::ModClient;
use crate::{kcl, lookup_the_nearest_file_dir};
use anyhow::{bail, Result};
use kclvm_config::modfile::KCL_MOD_FILE;
use kclvm_parser::LoadProgramOptions;
use kclvm_utils::pkgpath::rm_external_pkg_name;
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use std::ffi::OsStr;
use std::sync::Arc;
use std::{collections::HashMap, path::PathBuf, process::Command};
#[cfg(not(target_arch = "wasm32"))]
use {crate::client::ModClient, parking_lot::Mutex, std::sync::Arc};

/// `Toolchain` is a trait that outlines a standard set of operations that must be
/// implemented for a KCL module (mod), typically involving fetching metadata from,
Expand Down Expand Up @@ -99,11 +98,13 @@ impl<S: AsRef<OsStr> + Send + Sync> Toolchain for CommandToolchain<S> {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[derive(Default)]
pub struct NativeToolchain {
client: Arc<Mutex<ModClient>>,
}

#[cfg(not(target_arch = "wasm32"))]
impl Toolchain for NativeToolchain {
fn fetch_metadata(&self, manifest_path: PathBuf) -> Result<Metadata> {
let mut client = self.client.lock();
Expand Down

0 comments on commit 2519191

Please sign in to comment.