Much of the works was already done in https://github.com/otytlandsvik/SZ3-wasm Thanks @oletytlandsvik :)
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
stdenv,
|
||||||
|
fetchFromGitHub,
|
||||||
|
emscripten,
|
||||||
|
zstd,
|
||||||
|
}:
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "sz3-wasm";
|
||||||
|
# NOTE: the SZ3 `rev` below MUST stay in sync with `by-name/sz3` — the SZ3
|
||||||
|
# bitstream format is tied to a specific version (the stream embeds SZ3_DATA_VER
|
||||||
|
# and is checked on decode), so the wasm decoder must be built from the exact
|
||||||
|
# same source as whatever encoder produced the chunks.
|
||||||
|
version = "3.3.2";
|
||||||
|
|
||||||
|
src = fetchFromGitHub {
|
||||||
|
owner = "szcompressor";
|
||||||
|
repo = "SZ3";
|
||||||
|
rev = "34b36f2af0d43aa4f5dea0e39500e91f6d35c9cf";
|
||||||
|
sha256 = "0fckf5939m9d2w3095isnq3qfrz8fxpppn7y3c2hwzdh72vdzic7";
|
||||||
|
};
|
||||||
|
|
||||||
|
# zstd is SZ3's lossless backend. SZ3's tools/zstd uses CMake FetchContent to
|
||||||
|
# download zstd at build time, which does not work offline, so we compile the
|
||||||
|
# zstd C sources from nixpkgs' zstd source directly.
|
||||||
|
zstdSrc = zstd.src;
|
||||||
|
|
||||||
|
nativeBuildInputs = [ emscripten ];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
|
||||||
|
# Emscripten's cache in the nix store is read-only; give it a writable one.
|
||||||
|
export EM_CACHE=$TMPDIR/emcache
|
||||||
|
export HOME=$TMPDIR
|
||||||
|
mkdir -p $EM_CACHE
|
||||||
|
|
||||||
|
mkdir -p gen/SZ3
|
||||||
|
substitute include/SZ3/version.hpp.in gen/SZ3/version.hpp \
|
||||||
|
--subst-var-by PROJECT_NAME SZ3 \
|
||||||
|
--subst-var-by PROJECT_VERSION 3.3.2 \
|
||||||
|
--subst-var-by PROJECT_VERSION_MAJOR 3 \
|
||||||
|
--subst-var-by PROJECT_VERSION_MINOR 3 \
|
||||||
|
--subst-var-by PROJECT_VERSION_PATCH 2 \
|
||||||
|
--subst-var-by PROJECT_VERSION_TWEAK 0 \
|
||||||
|
--subst-var-by SZ3_DATA_VERSION 3.3.2
|
||||||
|
|
||||||
|
ZSTD_SRCS="$zstdSrc/lib/common/*.c $zstdSrc/lib/compress/*.c $zstdSrc/lib/decompress/*.c"
|
||||||
|
|
||||||
|
em++ -std=c++17 -O3 -DNDEBUG -sMEMORY64=1 \
|
||||||
|
-I gen -I include -I tools/sz3c/include -I "$zstdSrc/lib" \
|
||||||
|
tools/sz3c/src/sz3c.cpp $ZSTD_SRCS \
|
||||||
|
-sMODULARIZE=1 -sEXPORT_NAME=createSz3Module -sEXPORT_ES6=1 -sSINGLE_FILE=1 \
|
||||||
|
-sEXPORTED_FUNCTIONS='["_SZ_decompress","_malloc","_free"]' \
|
||||||
|
-sEXPORTED_RUNTIME_METHODS='["HEAPU8","HEAPF32","cwrap","ccall"]' \
|
||||||
|
-sALLOW_MEMORY_GROWTH=1 -sENVIRONMENT=web,worker \
|
||||||
|
-o sz3_decode.js
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
mkdir -p $out
|
||||||
|
install -m644 sz3_decode.js $out/sz3_decode.js
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "WebAssembly (wasm64) build of the SZ3 lossy decompressor C API for the browser";
|
||||||
|
homepage = "https://github.com/szcompressor/SZ3";
|
||||||
|
license = licenses.bsd3;
|
||||||
|
platforms = platforms.unix;
|
||||||
|
};
|
||||||
|
}
|
||||||
Generated
+27
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1783522502,
|
||||||
|
"narHash": "sha256-iffAls3iaNTyJC2faYcUXSI+Gp02cDjYl+MygxKl2GI=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "0bb7ec54c8483066ec9d7720e780a5caa71f8612",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user