Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: integrate libwasmvm into Go code and test Go project on Windows #360

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2ad89c4
Add build_shared_library_windows
webmaster128 Dec 13, 2022
613b226
Add wasmvm_test_windows CI job
webmaster128 Dec 1, 2022
7d6ba17
Avoid dot notation for relative paths in persist_to_workspace
webmaster128 Dec 1, 2022
3cb3019
Increase build_shared_library_windows machine size
webmaster128 Dec 1, 2022
628b0f2
Try windows path notation in persist_to_workspace of build_shared_lib…
webmaster128 Dec 1, 2022
8934a02
Attach workspace at C:/builds
webmaster128 Dec 1, 2022
66865fd
Harden ffiErrorWithMessage implementation
webmaster128 Dec 1, 2022
020f347
Make void return types more explicit
webmaster128 Dec 1, 2022
f5954dc
Use errno-sys to set errnos
webmaster128 Jan 16, 2023
f498c33
Try external linker
webmaster128 Dec 1, 2022
d2351bf
Make clippy happy
webmaster128 Dec 5, 2022
066dfa6
Advoid explicit linker setting
webmaster128 Dec 5, 2022
1716b61
Return error as integer in save_wasm/remove_wasm/load_wasm/pin/unpin
webmaster128 Jan 16, 2023
1be079d
Start NO_ERRNO docs
webmaster128 Dec 5, 2022
32a63f4
Let analyze_code return error
webmaster128 Dec 5, 2022
61143fc
Let get_metrics return error directly
webmaster128 Dec 5, 2022
5862e3f
Let init_cache return error directly
webmaster128 Dec 5, 2022
fd19fd6
Use CachePtr consistently and remove cache_t
webmaster128 Jan 16, 2023
aa3811e
Let C.instantiate and C.execute return error code directly
webmaster128 Dec 5, 2022
e9349e4
Let 2 arg C calls return error directly
webmaster128 Dec 5, 2022
2230a93
Remove unused ffiErrorWithMessage
webmaster128 Dec 5, 2022
9c168f5
Remove errno
webmaster128 Jan 16, 2023
92f47b5
Refactor ErrorCode
webmaster128 Dec 5, 2022
c083a37
Avoid FFI calls for errmsg, out that are not used
webmaster128 Dec 5, 2022
425cc11
Get CPU info of Windows machine
webmaster128 Dec 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 98 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ version: 2.1
orbs:
win: circleci/windows@5.0

commands:
show_cpu_info:
steps:
- run:
name: Show CPU info
command: |
set -o errexit
curl -sS -L --output py-cpuinfo.zip https://github.com/workhorsy/py-cpuinfo/archive/refs/tags/v9.0.0.zip
unzip -q py-cpuinfo.zip
python py-cpuinfo-*/cpuinfo/cpuinfo.py

jobs:
# All checks on the codebase that can run in parallel to build_shared_library
libwasmvm_sanity:
Expand Down Expand Up @@ -79,6 +90,7 @@ jobs:
- run:
name: Reset git config set by CircleCI to make Cargo work
command: git config --global --unset url.ssh://git@github.com.insteadof
- show_cpu_info
- run:
name: Install Rust
command: |
Expand Down Expand Up @@ -233,7 +245,7 @@ jobs:
name: Create release build of libwasmvm
command: make build-rust
- persist_to_workspace:
root: ./internal/api
root: internal/api
paths:
- libwasmvm.x86_64.so
- save_cache:
Expand All @@ -247,6 +259,55 @@ jobs:
- libwasmvm/target/release/deps
key: cargocache-v3-build_shared_library-rust:1.60.0-{{ checksum "libwasmvm/Cargo.lock" }}

# Analogue to build_shared_library this builds wasmvm.dll using a native Rust installation
# (i.e. no docker builders). In contrast to libwasmvm_sanity_windows this is a release build
# and gets its own build cache.
build_shared_library_windows:
executor:
name: win/default
size: large
shell: bash.exe
steps:
- checkout
- run:
name: Reset git config set by CircleCI to make Cargo work
command: git config --global --unset url.ssh://git@github.com.insteadof
- show_cpu_info
- run:
name: Install make
command: |
set -o errexit
choco install -y make
- run:
name: Install Rust
command: |
set -o errexit
curl -sS --output rustup-init.exe https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
./rustup-init.exe --no-modify-path --profile minimal --default-toolchain 1.60.0 -y
echo 'export PATH="$PATH;$USERPROFILE/.cargo/bin"' >> "$BASH_ENV"
- run:
name: Show Rust version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cachev4-build_shared_library_windows-rust:1.60.0-{{ checksum "libwasmvm/Cargo.lock" }}
- cachev4-build_shared_library_windows-rust:1.60.0-
- run:
name: Create release build of libwasmvm
command: make build-rust
- persist_to_workspace:
root: internal\api
paths:
- wasmvm.dll
- save_cache:
paths:
# ".." is the easiest way to get $HOME here (pwd is $HOME\project)
- ../.cargo/registry
- libwasmvm/target/release/.fingerprint
- libwasmvm/target/release/build
- libwasmvm/target/release/deps
key: cachev4-build_shared_library_windows-rust:1.60.0-{{ checksum "libwasmvm/Cargo.lock" }}

# Test the Go project
wasmvm_test:
docker:
Expand All @@ -269,6 +330,37 @@ jobs:
command: make test-safety
- run: make build-go

# Test the Go project on Windows
wasmvm_test_windows:
executor:
name: win/default
shell: bash.exe
environment:
GORACE: "halt_on_error=1"
steps:
- checkout
- show_cpu_info
- run:
name: Install make and mingw
# See https://github.com/docker/containerd-packaging/pull/294 for discussion around mingw version
command: |
set -o errexit
choco install -y make
choco install -y mingw --version 10.2.0 --allow-downgrade
- run:
name: Show Go version information
command: |
go version
make --version
- attach_workspace:
at: C:/builds
- run:
name: Copy .dll to system library path
command: cp /c/builds/wasmvm.dll /c/Windows/System32
- run:
name: Run Go tests
command: make test

test_alpine_build:
machine:
image: ubuntu-2004:2022.10.1
Expand Down Expand Up @@ -382,9 +474,13 @@ workflows:
filters: # required since other jobs with tag filters require this one
tags:
only: /.*/
- build_shared_library_windows
- wasmvm_test:
requires:
- build_shared_library
- wasmvm_test_windows:
requires:
- build_shared_library_windows
- build_static_lib:
requires:
- build_shared_library
Expand Down Expand Up @@ -418,6 +514,7 @@ workflows:
- format-scripts
- lint-scripts
- wasmvm_test
- wasmvm_test_windows
filters:
tags:
ignore:
Expand Down
21 changes: 21 additions & 0 deletions docs/NO_ERRNO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Why we are not using errno anymore

wasmvm up until 1.1.1 used errno to communicate errors over the FFI that
happened in the Rust code. The [errno](https://crates.io/crates/errno) crate was
used to set error values in Rust and
[cgo automatically read them](https://utcc.utoronto.ca/~cks/space/blog/programming/GoCgoErrorReturns)
and made them available in the error return value of
`ptr, err := C.init_cache(...)`.

Unfortunately errno does not work well for us when trying to support Windows. On
Windows, `errno`
[uses a Windows API](https://github.com/lambda-fairy/rust-errno/blob/v0.2.8/src/windows.rs#L60-L70)
which then is not what cgo expects. Also Rust's
[libc does not help us](https://github.com/rust-lang/libc/issues/1644) solving
the issue. Using the C errno variable via
[rust-errno](https://github.com/lambda-fairy/rust-errno) caused linker errors
using the Go "internal" linker.

In order to avoid wasting more time and remaining flexible when it comes to the
linker we use, we let all FFI functions return their error as an integer. The
result then goes into an output pointer.