Skip to content

Commit 6253fc8

Browse files
committed
wasm append output
1 parent 3f0a6fa commit 6253fc8

File tree

5 files changed

+87
-26
lines changed

5 files changed

+87
-26
lines changed

.github/workflows/build.yaml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
rustup update stable
4848
rustup component add rustfmt rust-src clippy
4949
rustup target add ${{ matrix.target }}
50+
rustup target add wasm32-unknown-unknown
51+
cargo install wasm-pack --force
5052
- name: Run Tests (univ)
5153
run: cargo test --features univ
5254
- name: Run Tests (wasm)
@@ -70,22 +72,35 @@ jobs:
7072
# APPLE_CODESIGN_PASSWORD: '${{ secrets.APPLE_CODESIGN_PASSWORD }}'
7173
# echo Key is $(echo $APPLE_CODESIGN_KEY | base64 -d | wc -c) bytes
7274
# rcodesign sign target/release/basjoofan --code-signature-flags=runtime --p12-password=$APPLE_CODESIGN_PASSWORD --p12-file=<(echo $APPLE_CODESIGN_KEY | base64 -d) --entitlements-xml-file=cli/entitlements.plist
73-
- name: Compress Archive (darwin or linux)
75+
# - name: Compress Archive (darwin or linux)
76+
# if: contains(matrix.target, 'darwin') || contains(matrix.target, 'linux')
77+
# run: zip -rj target/${{ matrix.target }}/release/basjoofan-${{ matrix.target }}.zip target/${{ matrix.target }}/release/basjoofan
78+
# - name: Compress Archive (windows)
79+
# if: contains(matrix.target, 'windows')
80+
# run: Compress-Archive -CompressionLevel Optimal -Force -Path target/${{ matrix.target }}/release/basjoofan.exe -DestinationPath target/${{ matrix.target }}/release/basjoofan-${{ matrix.target }}.zip
81+
- name: Echo Version (darwin or linux)
7482
if: contains(matrix.target, 'darwin') || contains(matrix.target, 'linux')
75-
run: zip -rj target/${{ matrix.target }}/release/basjoofan-${{ matrix.target }}.zip target/${{ matrix.target }}/release/basjoofan
76-
- name: Compress Archive (windows)
83+
run: echo version=$(grep '^version' ./cmd/Cargo.toml | head -1 | cut -d '"' -f2) >> $GITHUB_ENV
84+
- name: Naming (darwin or linux)
85+
if: contains(matrix.target, 'darwin') || contains(matrix.target, 'linux')
86+
run: mv target/${{ matrix.target }}/release/basjoofan target/${{ matrix.target }}/release/basjoofan-${{ env.version }}-${{ matrix.target }}
87+
- name: Echo Version (windows)
88+
if: contains(matrix.target, 'windows')
89+
run: echo version=$((Get-Content ./cmd/Cargo.toml | Select-String '^version').ToString().Split('"')[1]) >> $GITHUB_ENV
90+
- name: Naming (windows)
7791
if: contains(matrix.target, 'windows')
78-
run: Compress-Archive -CompressionLevel Optimal -Force -Path target/${{ matrix.target }}/release/basjoofan.exe -DestinationPath target/${{ matrix.target }}/release/basjoofan-${{ matrix.target }}.zip
92+
run: Rename-Item -Path target/${{ matrix.target }}/release/basjoofan.exe -NewName basjoofan-${{ env.version }}-${{ matrix.target }}.exe
7993
- name: Upload Artifacts
8094
uses: actions/upload-artifact@v4
8195
with:
82-
name: basjoofan-${{ matrix.target }}
83-
path: target/${{ matrix.target }}/release/basjoofan${{ contains(matrix.target, 'windows') && '.exe' || '' }}
96+
name: basjoofan-${{ env.version }}-${{ matrix.target }}
97+
path: target/${{ matrix.target }}/release/basjoofan-${{ env.version }}-${{ matrix.target }}${{ contains(matrix.target, 'windows') && '.exe' || '' }}
98+
if-no-files-found: error
8499
- name: Release Version
85100
uses: softprops/action-gh-release@v2
86101
if: startsWith(github.ref, 'refs/tags/')
87102
env:
88103
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89104
with:
90-
files: target/${{ matrix.target }}/release/basjoofan-${{ matrix.target }}.zip
105+
files: target/${{ matrix.target }}/release/basjoofan-${{ env.version }}-${{ matrix.target }}${{ contains(matrix.target, 'windows') && '.exe' || '' }}
91106
draft: true

cmd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cmd"
33
version = "0.1.0"
4-
description = "basjoofan command"
4+
description = "continuous test"
55
repository = "https://github.com/basjoofan/lib"
66
license = "MIT OR Apache-2.0"
77
authors = ["Lamb <lamb@basjoofan.com>"]

cmd/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use lib::Source;
44
use std::{path::PathBuf, time::Duration};
55

66
#[derive(Parser)]
7-
#[command(version, about, long_about = None)]
7+
#[command(name = env!("CARGO_BIN_NAME"), version, about, long_about = None)]
88
struct Interface {
99
#[command(subcommand)]
1010
command: Option<Commands>,

lib/src/http/wasm/client.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async fn fetch(request: &Request, content: Option<JsValue>, timeout: u32) -> Res
9090
#[cfg(test)]
9191
mod tests {
9292
use crate::http::Client;
93+
use js_sys::eval;
9394
use js_sys::BigInt;
9495
use wasm_bindgen::JsValue;
9596
use wasm_bindgen_test::*;
@@ -98,19 +99,19 @@ mod tests {
9899
// wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
99100

100101
fn setup() {
101-
let _ = js_sys::eval(
102+
let _ = eval(
102103
r#"
103-
globalThis.readFileContent = async function(filePath) {
104+
global.readFileContent = async function(filePath) {
104105
console.log(`Mock reading file in test: ${filePath}`);
105-
return new TextEncoder().encode(`Test content for ${filePath}`);
106+
return new TextEncoder().encode(`Mock content for ${filePath}`);
106107
};
107108
"#,
108109
);
109-
let _ = js_sys::eval(
110+
let _ = eval(
110111
r#"
111112
window.readFileContent = async function(filePath) {
112113
console.log(`Mock reading file in test: ${filePath}`);
113-
return new TextEncoder().encode(`Test content for ${filePath}`);
114+
return new TextEncoder().encode(`Mock content for ${filePath}`);
114115
};
115116
"#,
116117
);

lib/src/native.rs

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,67 @@
11
use crate::Context;
22
use crate::Value;
33

4-
pub fn println(values: Vec<Value>, context: &Context) -> Result<Value, String> {
5-
match format(values, context) {
6-
error @ Err(_) => error,
7-
Ok(value) => {
8-
println!("{value}");
9-
Ok(Value::Null)
4+
#[cfg(feature = "univ")]
5+
pub use univ::*;
6+
#[cfg(feature = "univ")]
7+
mod univ {
8+
use super::format;
9+
use crate::Context;
10+
use crate::Value;
11+
12+
pub fn println(values: Vec<Value>, context: &Context) -> Result<Value, String> {
13+
match format(values, context) {
14+
error @ Err(_) => error,
15+
Ok(value) => {
16+
println!("{value}");
17+
Ok(Value::Null)
18+
}
19+
}
20+
}
21+
22+
pub fn print(values: Vec<Value>, context: &Context) -> Result<Value, String> {
23+
match format(values, context) {
24+
error @ Err(_) => error,
25+
Ok(value) => {
26+
print!("{value}");
27+
Ok(Value::Null)
28+
}
1029
}
1130
}
1231
}
1332

14-
pub fn print(values: Vec<Value>, context: &Context) -> Result<Value, String> {
15-
match format(values, context) {
16-
error @ Err(_) => error,
17-
Ok(value) => {
18-
print!("{value}");
19-
Ok(Value::Null)
33+
#[cfg(feature = "wasm")]
34+
pub use wasm::*;
35+
#[cfg(feature = "wasm")]
36+
mod wasm {
37+
use super::format;
38+
use crate::Context;
39+
use crate::Value;
40+
use wasm_bindgen::prelude::wasm_bindgen;
41+
42+
#[wasm_bindgen]
43+
extern "C" {
44+
#[wasm_bindgen(js_name = appendOutput)]
45+
fn append_output(output: &str);
46+
}
47+
48+
pub fn println(values: Vec<Value>, context: &Context) -> Result<Value, String> {
49+
match format(values, context) {
50+
error @ Err(_) => error,
51+
Ok(value) => {
52+
append_output(format!("{value}\r\n").as_str());
53+
Ok(Value::Null)
54+
}
55+
}
56+
}
57+
58+
pub fn print(values: Vec<Value>, context: &Context) -> Result<Value, String> {
59+
match format(values, context) {
60+
error @ Err(_) => error,
61+
Ok(value) => {
62+
append_output(format!("{value}").as_str());
63+
Ok(Value::Null)
64+
}
2065
}
2166
}
2267
}

0 commit comments

Comments
 (0)