Skip to content
Draft

Wasm #534

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7486b0c
init
bokuweb Mar 17, 2024
bebb3fc
wip
bokuweb Aug 17, 2024
dd747d1
wip
bokuweb Aug 17, 2024
4c409ba
Merge remote-tracking branch 'origin/main' into wasm
bokuweb Aug 17, 2024
7746dc2
wip
bokuweb Aug 18, 2024
e483a64
wip
bokuweb Aug 24, 2024
423e49f
wip
bokuweb Sep 15, 2024
3243b9b
wip
bokuweb Sep 15, 2024
dc4f744
wip
bokuweb Sep 15, 2024
c3dab8a
wip
bokuweb Sep 15, 2024
847abdb
wip
bokuweb Sep 15, 2024
659b944
wip
bokuweb Sep 15, 2024
3d844f3
wip
bokuweb Sep 15, 2024
6f08f71
wip
bokuweb Sep 15, 2024
94f7e6a
wip
bokuweb Sep 16, 2024
e9ea0fe
wip
bokuweb Sep 22, 2024
505d51d
wip
bokuweb Sep 22, 2024
dfdaa40
wip
bokuweb Sep 23, 2024
c8ab836
wip
bokuweb Sep 23, 2024
7c84840
wip
bokuweb Sep 23, 2024
54f70d8
wip
bokuweb Sep 29, 2024
c10d750
wip
bokuweb Sep 29, 2024
15bbe8d
wip
bokuweb Sep 29, 2024
6adbc31
wip
bokuweb Sep 29, 2024
b1dfffe
wip
bokuweb Sep 30, 2024
c4ecf47
wip
bokuweb Sep 30, 2024
7f8957a
wip
bokuweb Sep 30, 2024
f224f7a
wip
bokuweb Sep 30, 2024
54c7184
wip
bokuweb Sep 30, 2024
01336ab
wip
bokuweb Sep 30, 2024
63bfe78
wip
bokuweb Sep 30, 2024
74d0081
wip
bokuweb Sep 30, 2024
47312c3
wip
bokuweb Sep 30, 2024
babdca5
wip
bokuweb Oct 2, 2024
cffec36
wip
bokuweb Nov 9, 2024
36e2bfe
0.0.0-experimental0
bokuweb Nov 9, 2024
3e5c7de
perf: improve perf
bokuweb Nov 10, 2024
3b6a822
update
bokuweb Nov 10, 2024
f5b262b
fix: image diff
bokuweb Dec 1, 2024
3c5e3b6
fix: wasm
bokuweb Dec 1, 2024
b11f5c3
fix: remove console.log
bokuweb Dec 1, 2024
b87f0b1
fix
bokuweb Dec 1, 2024
d1d3a5c
fix
bokuweb Jan 26, 2025
20af0a7
fix
bokuweb Jan 26, 2025
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
157 changes: 157 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,160 @@ report.html
/screenshot/*
sample/index.html
from-json.html
### Generated by gibo (https://github.com/simonwhitaker/gibo)
### https://raw.github.com/github/gitignore/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*


### https://raw.github.com/github/gitignore/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Rust.gitignore

# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

wasi-sdk-21.0
wasi-sdk-*
m.md

l
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
resolver = "2"
members = [
"crates/*",
]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

![reg-viz](https://raw.githubusercontent.com/reg-viz/artwork/master/repository/footer.png)

```
export WASI_VERSION_FULL=24.0
export WASI_SDK_PATH=`pwd`/wasi-sdk-${WASI_VERSION_FULL}
CFLAGS="--sysroot ${WASI_SDK_PATH}/share/wasi-sysroot" cargo build --release --target=wasm32-wasip1-threads
cp target/wasm32-wasip1-threads/release/reg_cli.wasm js/reg.wasm
```
13 changes: 13 additions & 0 deletions crates/reg_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "reg_cli"
path = "src/main.rs"

[dependencies]
reg_core = { path = "../reg_core" }
clap = { version = "4", features = ["derive"] }
serde_json = { version = "1.0" }
104 changes: 104 additions & 0 deletions crates/reg_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use clap::Parser;
use reg_core::{run, JsonReport, Options, Url};
use std::path::{Path, PathBuf};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[clap(index = 1)]
actual_dir: PathBuf,

#[clap(index = 2)]
expected_dir: PathBuf,

#[clap(index = 3)]
diff_dir: PathBuf,

#[arg(long)]
report: Option<PathBuf>,

#[arg(long)]
json: Option<PathBuf>,

#[arg(long = "matchingThreshold")]
matching_threshold: Option<f32>,

#[arg(long = "thresholdRate")]
threshold_rate: Option<f32>,

#[arg(long = "thresholdPixel")]
threshold_pixel: Option<u64>,

#[arg(long = "urlPrefix")]
url_prefix: Option<Url>,

#[arg(long)]
concurrency: Option<usize>,

#[arg(long = "enableAntialias")]
enable_antialias: Option<bool>,
}

#[cfg(not(all(target_os = "wasi", target_env = "p1")))]
pub fn main() {
let _ = inner();
}

#[cfg(all(target_os = "wasi", target_env = "p1"))]
pub fn main() {
// NOP
}

fn inner() -> Result<JsonReport, reg_core::CompareError> {
let args = Args::parse();

let options = Options {
report: args.report.as_deref().map(Path::new),
json: args.json.as_deref().map(Path::new),
matching_threshold: args.matching_threshold,
threshold_rate: args.threshold_rate,
threshold_pixel: args.threshold_pixel,
concurrency: args.concurrency,
enable_antialias: args.enable_antialias,
url_prefix: args.url_prefix,
};

run(args.actual_dir, args.expected_dir, args.diff_dir, options)
}

#[cfg(all(target_os = "wasi", target_env = "p1"))]
#[repr(C)]
pub struct WasmOutput {
pub len: usize,
pub buf: *mut u8,
}

#[cfg(all(target_os = "wasi", target_env = "p1"))]
#[no_mangle]
pub extern "C" fn wasm_main() -> *mut WasmOutput {
let res = inner();
if let Ok(res) = res {
let mut s = serde_json::to_string_pretty(&res).unwrap();

let len = s.len();
let ptr = s.as_mut_ptr();
std::mem::forget(s);

let output = Box::new(WasmOutput { len, buf: ptr });
Box::into_raw(output)
} else {
panic!("Failed to exec wasm main. readon {:?}", res);
}
}

#[cfg(all(target_os = "wasi", target_env = "p1"))]
#[no_mangle]
pub extern "C" fn free_wasm_output(ptr: *mut WasmOutput) {
if ptr.is_null() {
return;
}
unsafe {
let output = Box::from_raw(ptr);
Vec::from_raw_parts(output.buf, output.len, output.len);
}
}
26 changes: 26 additions & 0 deletions crates/reg_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "reg_core"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "reg_core"
path = "src/lib.rs"

[dependencies]
image-diff-rs = { git = "https://github.com/bokuweb/image-diff-rs.git" }
glob = "0.3.1"
rayon = "1.8"
mustache = "0.9.0"
serde = { version = "1.0.207", features = ["derive"] }
serde_json = "1.0.125"
bytes = "1.7.1"
urlencoding = "2.1.3"
pathdiff = "0.2.1"
path-clean = "1.0.1"
thiserror = "1.0"
url = "2.5.2"

[dev-dependencies]
14 changes: 14 additions & 0 deletions crates/reg_core/src/dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::path::{Path, PathBuf};

pub(crate) fn dirname(path: &Path) -> PathBuf {
if path.file_name().is_some() {
path.parent().unwrap_or_else(|| Path::new("")).to_path_buf()
} else {
path.to_path_buf()
}
}

pub(crate) fn resolve_dir(base: &Path, target: &Path) -> PathBuf {
let base_dir = dirname(base);
pathdiff::diff_paths(target, base_dir).expect("should resolve relative path.")
}
Loading
Loading