Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Polywrap Origin (0.9.5)
## Bugs
* [PR-1541](https://github.com/polywrap/toolchain/pull/1541) `polywrap` CLI: Update build images to use the latest multi-platform versions.

# Polywrap Origin (0.9.4)
## Bugs
* [PR-1372](https://github.com/polywrap/toolchain/pull/1372) `@polywrap/schema-parse`, `@polywrap/schema-compose`: Fixed a bug when importing type with map properties that use imported types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ const DEFAULTS_DIR = path.join(
export interface VMConfig {
defaultIncludes: string[];
baseImage: string;
version: string;
}

const CONFIGS: Record<BuildableLanguage, VMConfig> = {
"wasm/rust": {
defaultIncludes: ["Cargo.toml", "Cargo.lock"],
baseImage: "polywrap/vm-base-rs",
version: "0.2.0",
},
"wasm/assemblyscript": {
defaultIncludes: ["package.json", "package-lock.json", "yarn.lock"],
baseImage: "polywrap/vm-base-as",
version: "0.1.0",
},
};

Expand Down Expand Up @@ -187,9 +190,9 @@ export class DockerVMBuildStrategy extends BuildStrategy<void> {
this._volumePaths.project
)}:/project -v ${path.resolve(
this._volumePaths.linkedPackages
)}:/linked-packages ${cacheVolume} ${
CONFIGS[language].baseImage
}:latest /bin/bash --verbose /project/polywrap-build.sh`,
)}:/linked-packages ${cacheVolume} ${CONFIGS[language].baseImage}:${
CONFIGS[language].version
} /bin/bash --verbose /project/polywrap-build.sh`,
this.project.logger,
undefined,
undefined,
Expand All @@ -206,9 +209,9 @@ export class DockerVMBuildStrategy extends BuildStrategy<void> {
this._volumePaths.project
)}:/project -v ${path.resolve(
this._volumePaths.linkedPackages
)}:/linked-packages ${
CONFIGS[language].baseImage
}:latest /bin/bash -c "chmod -R 777 /project && chmod -R 777 /linked-packages"`,
)}:/linked-packages ${CONFIGS[language].baseImage}:${
CONFIGS[language].version
} /bin/bash -c "chmod -R 777 /project && chmod -R 777 /linked-packages"`,
this.project.logger
);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM rust:1.60.0 as base
FROM rust:1.66-alpine as base

# Install the wasm32 rust build target
RUN rustup target add wasm32-unknown-unknown

WORKDIR /build-deps

# Install curl
RUN apt-get update
RUN apt-get -y install curl clang llvm build-essential
RUN apk add curl pkgconfig openssl-dev bash

# Install clang
RUN apk add clang llvm build-base

# Install wasm-opt
RUN curl -L https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz | tar -xz \
Expand All @@ -16,16 +18,19 @@ RUN curl -L https://github.com/WebAssembly/binaryen/releases/download/version_10
&& rm -rf binary-version_101

# Install the toml-cli
RUN cargo install -f toml-cli
RUN cargo install toml-cli

# Install wasm-snip
RUN cargo install -f wasm-snip
RUN cargo install wasm-snip

# Install wasm-bindgen
RUN cargo install -f wasm-bindgen-cli
RUN cargo install wasm-bindgen-cli

# Install wasm-tools
RUN cargo install wasm-tools

# Install cargo-build-deps
RUN cargo install -f cargo-build-deps
RUN cargo install cargo-build-deps

{{#polywrap_linked_packages.length}}
WORKDIR /linked-packages
Expand Down Expand Up @@ -107,10 +112,15 @@ ENV WASM_INTERFACE_TYPES=1
# Run wasm-bindgen over the module, replacing all placeholder __wbindgen_... imports
RUN wasm-bindgen ./{{dir}}/target/wasm32-unknown-unknown/release/module.wasm --out-dir ./build --out-name bg_module.wasm

RUN wasm-snip ./build/bg_module.wasm -o ./build/snipped_module.wasm && \
# Run wasm-tools strip to remove the wasm-interface-types custom section
RUN wasm-tools strip ./build/bg_module.wasm -d wasm-interface-types -o ./build/strip_module.wasm && \
rm -rf ./build/bg_module.wasm

# Run wasm-snip to trip down the size of the binary, removing any dead code
RUN wasm-snip ./build/strip_module.wasm -o ./build/snipped_module.wasm && \
rm -rf ./build/strip_module.wasm

# Use wasm-opt to perform the "asyncify" post-processing step over all modules
RUN wasm-opt --asyncify -Os ./build/snipped_module.wasm -o ./build/wrap.wasm && \
rm -rf ./build/snipped_module.wasm
{{/polywrap_module}}
{{/polywrap_module}}
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
#!/bin/sh

# Install the wasm32 rust build target
rustup target add wasm32-unknown-unknown
export RUSTFLAGS="-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory"

# Install the toml-cli
cargo install toml-cli

# Install wasm-snip
cargo install wasm-snip

# Install wasm-bindgen
cargo install wasm-bindgen-cli

# Install wasm-tools
cargo install wasm-tools

# Ensure the module at {{dir}} has the crate-type = ["cdylib"]
toml set "$1"/Cargo.toml lib.crate-type ["cdylib"] > "$1"/Cargo-local.toml && \
rm -rf "$1"/Cargo.toml && \
mv "$1"/Cargo.toml "$1"/Cargo-bak.toml && \
mv "$1"/Cargo-local.toml "$1"/Cargo.toml

# Clean up artifacts left by the toml CLI program ("["cdylib"]" -> ["cdylib"])
sed -i 's/"\[cdylib\]"/\["cdylib"\]/g' "$1"/Cargo.toml
sed -i .bak 's/"\[cdylib\]"/\["cdylib"\]/g' "$1"/Cargo.toml && \
rm -rf "$1"/Cargo.toml.bak

# Ensure the package name = "module"
toml set "$1"/Cargo.toml package.name "module" > "$1"/Cargo-local.toml && \
rm -rf "$1"/Cargo.toml && \
mv "$1"/Cargo-local.toml "$1"/Cargo.toml

# Ensure the Wasm module is configured to use imported memory
export RUSTFLAGS="-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory"

# Build the module
cargo build --manifest-path "$1"/Cargo.toml \
--target wasm32-unknown-unknown --release

# Replace the modified Cargo.toml with the backup
rm -rf "$1"/Cargo.toml && mv "$1"/Cargo-bak.toml "$1"/Cargo.toml

# Enable the "WASM_INTERFACE_TYPES" feature, which will remove the __wbindgen_throw import.
# See: https://github.com/rustwasm/wasm-bindgen/blob/7f4663b70bd492278bf0e7bba4eeddb3d840c868/crates/cli-support/src/lib.rs#L397-L403
export WASM_INTERFACE_TYPES=1

# Run wasm-bindgen over the module, replacing all placeholder __wbindgen_... imports
wasm-bindgen "$1"/target/wasm32-unknown-unknown/release/module.wasm --out-dir "$2" --out-name bg_module.wasm
wasm-snip "$2"/bg_module.wasm -o "$2"/snipped_module.wasm && \
rm -rf "$2"/bg_module.wasm

# Run wasm-tools strip to remove the wasm-interface-types custom section
wasm-tools strip "$2"/bg_module.wasm -d wasm-interface-types -o "$2"/strip_module.wasm
rm -rf "$2"/bg_module.wasm

# Run wasm-snip to trip down the size of the binary, removing any dead code
wasm-snip "$2"/strip_module.wasm -o "$2"/snipped_module.wasm
rm -rf "$2"/strip_module.wasm

# Use wasm-opt to perform the "asyncify" post-processing step over all modules
npx wasm-opt --asyncify -Os "$2"/snipped_module.wasm -o "$2"/wrap.wasm
rm -rf "$2"/snipped_module.wasm
rm -rf "$2"/snipped_module.wasm
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM rust:1.60.0 as base
FROM rust:1.66-alpine as base

# Install the wasm32 rust build target
RUN rustup target add wasm32-unknown-unknown

WORKDIR /build-deps

# Install curl
RUN apt-get update
RUN apt-get -y install curl clang llvm build-essential
RUN apk add curl pkgconfig openssl-dev bash

# Install clang
RUN apk add clang llvm build-base

# Install wasm-opt
RUN curl -L https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz | tar -xz \
Expand All @@ -16,18 +18,25 @@ RUN curl -L https://github.com/WebAssembly/binaryen/releases/download/version_10
&& rm -rf binary-version_101

# Install the toml-cli
RUN cargo install -f toml-cli
RUN cargo install toml-cli

# Install wasm-snip
RUN cargo install -f wasm-snip
RUN cargo install wasm-snip

# Install wasm-bindgen
RUN cargo install -f wasm-bindgen-cli
RUN cargo install wasm-bindgen-cli

# Install wasm-tools
RUN cargo install wasm-tools

# Install cargo-build-deps
RUN cargo install -f cargo-build-deps
RUN cargo install cargo-build-deps

# Ensure the Wasm module is configured to use imported memory
ENV RUSTFLAGS="-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory"

# Enable the "WASM_INTERFACE_TYPES" feature, which will remove the __wbindgen_throw import.
# See: https://github.com/rustwasm/wasm-bindgen/blob/7f4663b70bd492278bf0e7bba4eeddb3d840c868/crates/cli-support/src/lib.rs#L397-L403
ENV WASM_INTERFACE_TYPES=1

WORKDIR /project
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set -e

{{#polywrap_linked_packages.length}}
# Link any local packages
{{#polywrap_linked_packages}}
toml set ./{{#polywrap_module}}{{dir}}{{/polywrap_module}}/Cargo.toml dependencies.{{name}}.path /linked-packages/{{name}} > ./{{#polywrap_module}}{{dir}}{{/polywrap_module}}/Cargo-local.toml
rm -rf ./{{#polywrap_module}}{{dir}}{{/polywrap_module}}/Cargo.toml
Expand All @@ -9,26 +10,39 @@ toml set ./{{#polywrap_module}}{{dir}}{{/polywrap_module}}/Cargo.toml dependenci
{{/polywrap_linked_packages.length}}

{{#polywrap_module}}
# Ensure the module at {{dir}} has the crate-type = ["cdylib"]
toml set ./{{dir}}/Cargo.toml lib.crate-type ["cdylib"] > ./{{dir}}/Cargo-local.toml
rm -rf ./{{dir}}/Cargo.toml
mv ./{{dir}}/Cargo-local.toml ./{{dir}}/Cargo.toml

# Clean up artifacts left by the toml CLI program ("["cdylib"]" -> ["cdylib"])
sed -i 's/\"\[cdylib\]\"/\[\"cdylib\"\]/g' ./{{dir}}/Cargo.toml

# Ensure the package name = "module"
toml set ./{{dir}}/Cargo.toml package.name "module" > ./{{dir}}/Cargo-local.toml
rm -rf ./{{dir}}/Cargo.toml
mv ./{{dir}}/Cargo-local.toml ./{{dir}}/Cargo.toml

# Build the module
cargo build --manifest-path ./{{dir}}/Cargo.toml \
--target wasm32-unknown-unknown --release

# Make the build directory
rm -rf ./build
mkdir ./build

# Run wasm-bindgen over the module, replacing all placeholder __wbindgen_... imports
wasm-bindgen ./{{dir}}/target/wasm32-unknown-unknown/release/module.wasm --out-dir ./build --out-name bg_module.wasm

wasm-snip ./build/bg_module.wasm -o ./build/snipped_module.wasm
# Run wasm-tools strip to remove the wasm-interface-types custom section
wasm-tools strip ./build/bg_module.wasm -d wasm-interface-types -o ./build/strip_module.wasm
rm -rf ./build/bg_module.wasm

# Run wasm-snip to trip down the size of the binary, removing any dead code
wasm-snip ./build/strip_module.wasm -o ./build/snipped_module.wasm
rm -rf ./build/strip_module.wasm

# Use wasm-opt to perform the "asyncify" post-processing step over all modules
wasm-opt --asyncify -Os ./build/snipped_module.wasm -o ./build/wrap.wasm
rm -rf ./build/snipped_module.wasm
{{/polywrap_module}}