mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Switch to stable Rust
Nightly is no longer necessary for wee_alloc, so we don't need to rely on unstable versions of Rust anymore. As a bonus, this reduces size of each Rust-related Docker image by >1 GB: - `squoosh-rotate`: 2.94GB -> 1.87GB - `squoosh-resize`: 3.09GB -> 2.02GB - `squoosh-hqx`: 3.13GB -> 2.06GB
This commit is contained in:
@@ -10,8 +10,7 @@ RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|||||||
make install
|
make install
|
||||||
|
|
||||||
FROM rust
|
FROM rust
|
||||||
RUN rustup install nightly && \
|
RUN rustup target add wasm32-unknown-unknown && \
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown && \
|
|
||||||
cargo install wasm-pack
|
cargo install wasm-pack
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
COPY --from=0 /opt/wabt /opt/wabt
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ echo "============================================="
|
|||||||
echo "Compiling wasm"
|
echo "Compiling wasm"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
rustup run nightly \
|
wasm-pack build --target no-modules
|
||||||
wasm-pack build --target no-modules
|
|
||||||
wasm-strip pkg/squooshhqx_bg.wasm
|
wasm-strip pkg/squooshhqx_bg.wasm
|
||||||
echo "Optimising Wasm so it doesn't break Chrome (this takes like 10-15mins. get a cup of tea)"
|
echo "Optimising Wasm so it doesn't break Chrome (this takes like 10-15mins. get a cup of tea)"
|
||||||
echo "Once https://crbug.com/974804 is fixed, we can remove this step"
|
echo "Once https://crbug.com/974804 is fixed, we can remove this step"
|
||||||
|
|||||||
@@ -19,16 +19,16 @@
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArrayU32FromWasm(ptr, len) {
|
let cachegetInt32Memory = null;
|
||||||
return getUint32Memory().subarray(ptr / 4, ptr / 4 + len);
|
function getInt32Memory() {
|
||||||
|
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) {
|
||||||
|
cachegetInt32Memory = new Int32Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachegetInt32Memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cachedGlobalArgumentPtr = null;
|
function getArrayU32FromWasm(ptr, len) {
|
||||||
function globalArgumentPtr() {
|
return getUint32Memory().subarray(ptr / 4, ptr / 4 + len);
|
||||||
if (cachedGlobalArgumentPtr === null) {
|
|
||||||
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
|
||||||
}
|
|
||||||
return cachedGlobalArgumentPtr;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {Uint32Array} input_image
|
* @param {Uint32Array} input_image
|
||||||
@@ -38,18 +38,12 @@
|
|||||||
* @returns {Uint32Array}
|
* @returns {Uint32Array}
|
||||||
*/
|
*/
|
||||||
__exports.resize = function(input_image, input_width, input_height, factor) {
|
__exports.resize = function(input_image, input_width, input_height, factor) {
|
||||||
const ptr0 = passArray32ToWasm(input_image);
|
const retptr = 8;
|
||||||
const len0 = WASM_VECTOR_LEN;
|
const ret = wasm.resize(retptr, passArray32ToWasm(input_image), WASM_VECTOR_LEN, input_width, input_height, factor);
|
||||||
const retptr = globalArgumentPtr();
|
const memi32 = getInt32Memory();
|
||||||
wasm.resize(retptr, ptr0, len0, input_width, input_height, factor);
|
const v0 = getArrayU32FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
|
||||||
const mem = getUint32Memory();
|
wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 4);
|
||||||
const rustptr = mem[retptr / 4];
|
return v0;
|
||||||
const rustlen = mem[retptr / 4 + 1];
|
|
||||||
|
|
||||||
const realRet = getArrayU32FromWasm(rustptr, rustlen).slice();
|
|
||||||
wasm.__wbindgen_free(rustptr, rustlen * 4);
|
|
||||||
return realRet;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function init(module) {
|
function init(module) {
|
||||||
|
|||||||
3
codecs/hqx/pkg/squooshhqx_bg.d.ts
vendored
3
codecs/hqx/pkg/squooshhqx_bg.d.ts
vendored
@@ -1,6 +1,5 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
export const memory: WebAssembly.Memory;
|
export const memory: WebAssembly.Memory;
|
||||||
export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
||||||
export function __wbindgen_global_argument_ptr(): number;
|
|
||||||
export function __wbindgen_malloc(a: number): number;
|
export function __wbindgen_malloc(a: number): number;
|
||||||
export function __wbindgen_free(a: number, b: number): void;
|
export function __wbindgen_free(a: number, b: number): void;
|
||||||
|
export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||||
|
|||||||
Binary file not shown.
@@ -9,8 +9,7 @@ RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|||||||
make install
|
make install
|
||||||
|
|
||||||
FROM rust
|
FROM rust
|
||||||
RUN rustup install nightly && \
|
RUN rustup target add wasm32-unknown-unknown && \
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown && \
|
|
||||||
cargo install wasm-pack
|
cargo install wasm-pack
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
COPY --from=0 /opt/wabt /opt/wabt
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ echo "============================================="
|
|||||||
echo "Compiling wasm"
|
echo "Compiling wasm"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
rustup run nightly \
|
wasm-pack build --target no-modules
|
||||||
wasm-pack build --target no-modules
|
|
||||||
wasm-strip pkg/resize_bg.wasm
|
wasm-strip pkg/resize_bg.wasm
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
|
|||||||
Binary file not shown.
@@ -9,8 +9,7 @@ RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|||||||
make install
|
make install
|
||||||
|
|
||||||
FROM rust
|
FROM rust
|
||||||
RUN rustup install nightly && \
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown
|
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
COPY --from=0 /opt/wabt /opt/wabt
|
||||||
ENV PATH="/opt/wabt/bin:${PATH}"
|
ENV PATH="/opt/wabt/bin:${PATH}"
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ echo "============================================="
|
|||||||
echo "Compiling wasm"
|
echo "Compiling wasm"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
rustup run nightly \
|
cargo build \
|
||||||
cargo build \
|
|
||||||
--target wasm32-unknown-unknown \
|
--target wasm32-unknown-unknown \
|
||||||
--release
|
--release
|
||||||
cp target/wasm32-unknown-unknown/release/rotate.wasm .
|
cp target/wasm32-unknown-unknown/release/rotate.wasm .
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user