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:
Ingvar Stepanyan
2019-08-02 15:55:54 +01:00
parent 3932ee2c00
commit 499956e216
11 changed files with 21 additions and 34 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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) {

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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}"

View File

@@ -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.