fix WASM build

improve Earthfile with better unit tests and updated dependencies
This commit is contained in:
Christien Rioux 2024-04-28 16:15:09 -04:00
parent eba349d22c
commit b0ccd04a9f
6 changed files with 112 additions and 63 deletions

97
Cargo.lock generated
View File

@ -294,7 +294,7 @@ checksum = "136d4d23bcc79e27423727b36823d86233aad06dfea531837b038394d11e9928"
dependencies = [
"concurrent-queue",
"event-listener 5.3.0",
"event-listener-strategy 0.5.1",
"event-listener-strategy 0.5.2",
"futures-core",
"pin-project-lite",
]
@ -307,7 +307,7 @@ checksum = "b10202063978b3351199d68f8b22c4e47e4b1b822f8d43fd862d5ea8c006b29a"
dependencies = [
"async-task",
"concurrent-queue",
"fastrand 2.0.2",
"fastrand 2.1.0",
"futures-lite 2.3.0",
"slab",
]
@ -488,9 +488,9 @@ dependencies = [
[[package]]
name = "async-task"
version = "4.7.0"
version = "4.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799"
checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
[[package]]
name = "async-trait"
@ -776,18 +776,16 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae"
[[package]]
name = "blocking"
version = "1.5.1"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118"
checksum = "495f7104e962b7356f0aeb34247aca1fe7d2e783b346582db7f2904cb5717e88"
dependencies = [
"async-channel 2.2.1",
"async-lock 3.3.0",
"async-task",
"fastrand 2.0.2",
"futures-io",
"futures-lite 2.3.0",
"piper",
"tracing",
]
[[package]]
@ -1561,7 +1559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
dependencies = [
"cfg-if 1.0.0",
"hashbrown 0.14.3",
"hashbrown 0.14.5",
"lock_api",
"once_cell",
"parking_lot_core 0.9.10",
@ -1569,9 +1567,9 @@ dependencies = [
[[package]]
name = "data-encoding"
version = "2.5.0"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2"
[[package]]
name = "der"
@ -1866,6 +1864,8 @@ dependencies = [
"concurrent-queue",
"parking",
"pin-project-lite",
"portable-atomic",
"portable-atomic-util",
]
[[package]]
@ -1880,9 +1880,9 @@ dependencies = [
[[package]]
name = "event-listener-strategy"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "332f51cb23d20b0de8458b86580878211da09bcd4503cb579c225b3d124cabb3"
checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1"
dependencies = [
"event-listener 5.3.0",
"pin-project-lite",
@ -1921,9 +1921,9 @@ dependencies = [
[[package]]
name = "fastrand"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984"
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
[[package]]
name = "fdeflate"
@ -2129,7 +2129,7 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5"
dependencies = [
"fastrand 2.0.2",
"fastrand 2.1.0",
"futures-core",
"futures-io",
"parking",
@ -2379,9 +2379,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.14.3"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [
"ahash 0.8.11",
"allocator-api2",
@ -2393,7 +2393,7 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7"
dependencies = [
"hashbrown 0.14.3",
"hashbrown 0.14.5",
]
[[package]]
@ -2728,7 +2728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown 0.14.3",
"hashbrown 0.14.5",
]
[[package]]
@ -3917,7 +3917,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4"
dependencies = [
"atomic-waker",
"fastrand 2.0.2",
"fastrand 2.1.0",
"futures-io",
]
@ -3998,6 +3998,21 @@ dependencies = [
"universal-hash",
]
[[package]]
name = "portable-atomic"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
[[package]]
name = "portable-atomic-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1a7411625b38d51b41421c6333976adffd4674a925a978856734a2dc853449b"
dependencies = [
"portable-atomic",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
@ -4504,9 +4519,9 @@ dependencies = [
[[package]]
name = "schemars"
version = "0.8.16"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29"
checksum = "7f55c82c700538496bdc329bb4918a81f87cc8888811bd123cf325a0f2f8d309"
dependencies = [
"dyn-clone",
"schemars_derive",
@ -4516,14 +4531,14 @@ dependencies = [
[[package]]
name = "schemars_derive"
version = "0.8.16"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967"
checksum = "83263746fe5e32097f06356968a077f96089739c927a61450efa069905eec108"
dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals 0.26.0",
"syn 1.0.109",
"serde_derive_internals 0.29.0",
"syn 2.0.60",
]
[[package]]
@ -4614,9 +4629,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.198"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
dependencies = [
"serde_derive",
]
@ -4673,9 +4688,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.198"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
dependencies = [
"proc-macro2",
"quote",
@ -4684,20 +4699,20 @@ dependencies = [
[[package]]
name = "serde_derive_internals"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c"
checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.60",
]
[[package]]
name = "serde_derive_internals"
version = "0.28.0"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509"
checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3"
dependencies = [
"proc-macro2",
"quote",
@ -5952,7 +5967,7 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3dabbda02cfe176635dcaa18a021416ff2eb4d0b47a913e3fdc7f62049d7b1"
dependencies = [
"hashbrown 0.14.3",
"hashbrown 0.14.5",
"serde",
]
@ -6307,12 +6322,14 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "wg"
version = "0.3.2"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f390449c16e0679435fc97a6b49d24e67f09dd05fea1de54db1b60902896d273"
checksum = "dadf90865f15d5c2d87f126a56ce3715b3a233641acdd10f59200aa7f4c81fb9"
dependencies = [
"atomic-waker",
"event-listener 5.3.0",
"futures-core",
"parking_lot 0.12.2",
"pin-project-lite",
"triomphe",
]

View File

@ -14,11 +14,15 @@ VERSION 0.7
# Start with older Ubuntu to ensure GLIBC symbol versioning support for older linux
# Ensure we are using an amd64 platform because some of these targets use cross-platform tooling
FROM ubuntu:18.04
ENV ZIG_VERSION=0.11.0-dev.3978+711b4e93e
ENV ZIG_VERSION=0.13.0-dev.46+3648d7df1
ENV RUSTUP_HOME=/usr/local/rustup
ENV RUSTUP_DIST_SERVER=https://static.rust-lang.org
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=$PATH:/usr/local/cargo/bin:/usr/local/zig
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV RUST_BACKTRACE=1
WORKDIR /veilid
# Install build prerequisites & setup required directories
@ -44,12 +48,13 @@ deps-rust:
RUN rustup target add x86_64-linux-android
# WASM
RUN rustup target add wasm32-unknown-unknown
RUN cargo install wasm-pack wasm-bindgen-cli
# Caching tool
RUN cargo install cargo-chef
# Install Linux cross-platform tooling
RUN curl -O https://ziglang.org/builds/zig-linux-x86_64-$ZIG_VERSION.tar.xz
RUN tar -C /usr/local -xJf zig-linux-x86_64-$ZIG_VERSION.tar.xz
RUN mv /usr/local/zig-linux-x86_64-$ZIG_VERSION /usr/local/zig
RUN curl -O https://ziglang.org/builds/zig-linux-$(arch)-$ZIG_VERSION.tar.xz
RUN tar -C /usr/local -xJf zig-linux-$(arch)-$ZIG_VERSION.tar.xz
RUN mv /usr/local/zig-linux-$(arch)-$ZIG_VERSION /usr/local/zig
RUN cargo install cargo-zigbuild
SAVE ARTIFACT $RUSTUP_HOME rustup
SAVE ARTIFACT $CARGO_HOME cargo
@ -112,7 +117,7 @@ code-linux:
FROM $CI_REGISTRY_IMAGE/build-cache:latest
# FROM registry.gitlab.com/veilid/build-cache:latest
END
COPY --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
COPY --dir .cargo build_docs.sh files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
# Code + Linux + Android deps
code-android:
@ -167,22 +172,37 @@ build-android:
SAVE ARTIFACT ./target/x86_64-linux-android AS LOCAL ./target/artifacts/x86_64-linux-android
# Unit tests
unit-tests-linux:
unit-tests-clippy-linux:
FROM +code-linux
ENV RUST_BACKTRACE=1
RUN cargo clippy
unit-tests-docs-linux:
FROM +code-linux
RUN ./build_docs.sh
unit-tests-native-linux:
FROM +code-linux
RUN cargo test -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core
# TODO: Change t0 cross so that they work on any platform
unit-tests-linux-amd64:
unit-tests-wasm-linux:
FROM +code-linux
ENV RUST_BACKTRACE=1
RUN cargo test --target x86_64-unknown-linux-gnu --release -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core
# Just run build now because actual unit tests require network access
# which should be moved to a separate integration test
RUN veilid-wasm/wasm_build.sh
unit-tests-linux-arm64:
FROM +code-linux
ENV RUST_BACKTRACE=1
RUN cargo test --target aarch64-unknown-linux-gnu --release -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core
unit-tests-linux:
WAIT
BUILD +unit-tests-clippy-linux
END
WAIT
BUILD +unit-tests-docs-linux
END
WAIT
BUILD +unit-tests-native-linux
END
WAIT
BUILD +unit-tests-wasm-linux
END
# Package
package-linux-amd64-deb:

View File

@ -438,6 +438,14 @@ impl Network {
None
}
pub fn get_preferred_local_address_by_key(
&self,
_pt: ProtocolType,
_at: AddressType,
) -> Option<SocketAddr> {
None
}
//////////////////////////////////////////
pub fn set_needs_public_dial_info_check(

View File

@ -80,7 +80,7 @@ rpassword = "^7"
hostname = "^0"
stop-token = { version = "^0", default-features = false }
sysinfo = { version = "^0.30.6" }
wg = "0.3.2"
wg = { version = "^0.9.1", features = ["future"] }
[target.'cfg(windows)'.dependencies]
windows-service = "^0"

View File

@ -282,7 +282,7 @@ pub fn listen_address_to_socket_addrs(listen_address: &str) -> Result<Vec<Socket
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
use core::str::FromStr;
vec![SocketAddr::from_str(listen_address_with_port).map_err(|e| format!("Unable to parse address: {}",e))?]
vec![SocketAddr::from_str(&listen_address_with_port).map_err(|e| format!("Unable to parse address: {}",e))?]
} else {
listen_address_with_port
.to_socket_addrs()

View File

@ -18,13 +18,13 @@ else
# some systems may have the major LLVM version suffixed on the LLVM binaries - and we need `true` at the end because the whole script will fail with a nonzero return if something goes wrong here
DWARFDUMP=`which llvm-dwarfdump || find ${PATH//:/\/ } -name 'llvm-dwarfdump*' 2>/dev/null | head -n1 || true`
if [[ "${DWARFDUMP}" == "" ]]; then
echo "llvm-dwarfdump not found"
echo "llvm-dwarfdump not found"
fi
fi
if [[ "$1" == "release" ]]; then
OUTPUTDIR=../target/wasm32-unknown-unknown/release/pkg
INPUTDIR=../target/wasm32-unknown-unknown/release
OUTPUTDIR=$SCRIPTDIR/../target/wasm32-unknown-unknown/release/pkg
INPUTDIR=$SCRIPTDIR/../target/wasm32-unknown-unknown/release
# Path to, but not including, the cargo workspace ("veilid")
WORKSPACE_PARENT=$(dirname $(dirname $(cargo locate-project --workspace --message-format=plain)))
@ -40,13 +40,17 @@ if [[ "$1" == "release" ]]; then
wasm-bindgen --out-dir $OUTPUTDIR --target web --weak-refs $INPUTDIR/veilid_wasm.wasm
wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
else
OUTPUTDIR=../target/wasm32-unknown-unknown/debug/pkg
INPUTDIR=../target/wasm32-unknown-unknown/debug
OUTPUTDIR=$SCRIPTDIR/../target/wasm32-unknown-unknown/debug/pkg
INPUTDIR=$SCRIPTDIR/../target/wasm32-unknown-unknown/debug
RUSTFLAGS="-O -g $RUSTFLAGS" cargo build --target wasm32-unknown-unknown
mkdir -p $OUTPUTDIR
wasm-bindgen --out-dir $OUTPUTDIR --target web --weak-refs --keep-debug --debug $INPUTDIR/veilid_wasm.wasm
./wasm-sourcemap.py $OUTPUTDIR/veilid_wasm_bg.wasm -o $OUTPUTDIR/veilid_wasm_bg.wasm.map --dwarfdump $DWARFDUMP
if [[ -f "$DWARFDUMP" ]]; then
./wasm-sourcemap.py $OUTPUTDIR/veilid_wasm_bg.wasm -o $OUTPUTDIR/veilid_wasm_bg.wasm.map --dwarfdump $DWARFDUMP
else
echo "not generating sourcemaps because llvm-dwarfdump was not found"
fi
# wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
fi