Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Aug 14, 2024
1 parent d278efb commit 6d061d8
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 82 deletions.
58 changes: 38 additions & 20 deletions codecs/resize/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 43 additions & 49 deletions codecs/resize/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,70 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/24.05";
flake-utils.url = "github:numtide/flake-utils";
fenix.url = "github:nix-community/fenix";
wasm-bindgen = {
url = "../../nix/wasm-bindgen";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
rust-helpers = {
url = "../../nix/rust-helpers";
inputs.nixpkgs.follows = "nixpkgs";
};
squoosh-codec-builders = {
url = "../../nix/squoosh-codec-builders";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-helpers.follows = "rust-helpers";
inputs.wasm-bindgen.follows = "wasm-bindgen";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
fenix,
wasm-bindgen,
squoosh-codec-builders,
}:
flake-utils.lib.eachDefaultSystem (
system:
with nixpkgs.legacyPackages.${system};
let
target = "wasm32-unknown-unknown";
pkgs = nixpkgs.legacyPackages.${system};
toolchain =
with fenix.packages.${system};
combine [
stable.rustc
stable.cargo
targets.${target}.stable.rust-std
];
src = ./.;

rustPlatform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};

cargoLockFile = "${src}/Cargo.lock";

vendor = rustPlatform.importCargoLock {
lockFile = cargoLockFile;
};

wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock {
inherit system cargoLockFile;
sha256 = "sha256-HTElSB76gqCpDu8S0ZJlfd/S4ftMrbwxFgJM9OXBRz8=";
};
in
with pkgs;
# wasm-bindgen-bin = wasm-bindgen.lib.buildFromCargoLock {
# inherit system cargoLock;
# sha256 = "sha256-HTElSB76gqCpDu8S0ZJlfd/S4ftMrbwxFgJM9OXBRz8=";
# };
{
packages = rec {
default = resize-squoosh;
resize-squoosh = stdenv.mkDerivation {
name = "squoosh-resize";
inherit src;
nativeBuildInputs = [
toolchain
wasm-bindgen-bin
];
dontConfigure = true;
buildPhase = ''
runHook preBuild
export CARGO_HOME=$TMPDIR/.cargo
cargo build \
--config 'source.crates-io.replace-with="vendored-sources"' \
--config 'source.vendored-sources.directory="${vendor}"' \
--offline \
--target ${target} -r
wasm-bindgen --target web --out-dir $out ./target/wasm32-unknown-unknown/release/*.wasm
runHook postBuild
'';
dontInstall = true;
resize-squoosh = squoosh-codec-builders.lib.buildSquooshCodecRust {
name = "resize-squoosh";
inherit system src;
cargoLock = {
lockFile = "${src}/Cargo.lock";
};
};
# resize-squoosh = stdenv.mkDerivation {
# name = "squoosh-resize";
# inherit src;
# nativeBuildInputs = [
# toolchain
# wasm-bindgen-bin
# ];
# dontConfigure = true;
# buildPhase = ''
# runHook preBuild
# export CARGO_HOME=$TMPDIR/.cargo
# cargo build \
# --config 'source.crates-io.replace-with="vendored-sources"' \
# --config 'source.vendored-sources.directory="${vendoredDependencies}"' \
# --offline \
# --target ${target} -r
# wasm-bindgen --target web --out-dir $out ./target/wasm32-unknown-unknown/release/*.wasm
# runHook postBuild
# '';
# dontInstall = true;
# };

installScript = writeShellScriptBin "install.sh" ''
${pkgs.coreutils}/bin/mkdir -p wasm_build
Expand Down
34 changes: 34 additions & 0 deletions codecs/resize/wasm_build/squoosh_resize.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Uint8Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} output_width
* @param {number} output_height
* @param {number} typ_idx
* @param {boolean} premultiply
* @param {boolean} color_space_conversion
* @returns {Uint8ClampedArray}
*/
export function resize(input_image: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, typ_idx: number, premultiply: boolean, color_space_conversion: boolean): Uint8ClampedArray;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
}

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
Loading

0 comments on commit 6d061d8

Please sign in to comment.