diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml new file mode 100644 index 0000000..838b91d --- /dev/null +++ b/.github/workflows/wasm.yml @@ -0,0 +1,30 @@ +name: WASM + +on: + push: + pull_request: + schedule: + - cron: "35 2 * * *" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Add target + run: rustup target add wasm32-unknown-unknown + - name: Run build + run: cargo build --verbose + - name: Setup emsdk with cache + uses: mymindstorm/setup-emsdk@v11 + with: + version: 1.38.40 + actions-cache-folder: 'emsdk-cache' + - name: Install vcpkg + run: | + git clone https://github.com/Microsoft/vcpkg.git vcp + vcp/bootstrap-vcpkg.sh + - name: Run integration tests + run: | + tests/wasm.sh diff --git a/README.md b/README.md index f5aa3b9..0e248b5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# vcpkg-rs [![Windows](https://github.com/mcgoo/vcpkg-rs/workflows/Windows/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3AWindows) [![macOS](https://github.com/mcgoo/vcpkg-rs/workflows/macOS/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3AmacOS) [![Linux](https://github.com/mcgoo/vcpkg-rs/workflows/Linux/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3ALinux) +# vcpkg-rs [![Windows](https://github.com/mcgoo/vcpkg-rs/workflows/Windows/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3AWindows) [![macOS](https://github.com/mcgoo/vcpkg-rs/workflows/macOS/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3AmacOS) [![Linux](https://github.com/mcgoo/vcpkg-rs/workflows/Linux/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3ALinux) [![WASM](https://github.com/mcgoo/vcpkg-rs/workflows/Linux/badge.svg?branch=master)](https://github.com/mcgoo/vcpkg-rs/actions?query=workflow%3AWASM) [Documentation](https://docs.rs/vcpkg) [Changelog](CHANGELOG.md) diff --git a/src/lib.rs b/src/lib.rs index b586b96..87e13f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,17 @@ //! generate dynamically linked binaries, in which case you will have to arrange for //! dlls from your Vcpkg installation to be available in your path. //! +//! ## WASM 32 +//! +//! At this time, vcpkg has a single triplet for wasm32, wasm32-emscripten, +//! while rust has several targets for wasm32. +//! Currently all of these targets are mapped to wasm32-emscripten triplet. +//! +//! You can open an [issue](https://github.com/mcgoo/vcpkg-rs/issue) +//! if more wasm32 triplets come to vcpkg. +//! And just like other target, it is possibleto select a custom triplet +//! using the `VCPKGRS_TRIPLET` environment variable. +//! //! # Environment variables //! //! A number of environment variables are available to globally configure which @@ -58,7 +69,7 @@ //! //! * `VCPKG_INSTALLED_ROOT` - Set the directory for the vcpkg installed directory. Corresponding to //! `--x-install-root` flag in `vcpkg install` command. -//! A typical use case is to set it to `vcpkg_installed` directory under build directory +//! A typical use case is to set it to `vcpkg_installed` directory under build directory //! to adapt [manifest mode of vcpkg](https://learn.microsoft.com/en-us/vcpkg/users/manifests). //! If set, this will override the default value of `VCPKG_ROOT/installed`. //! @@ -734,13 +745,13 @@ fn load_ports(target: &VcpkgTarget) -> Result, Error> { // load updates to the status file that have yet to be normalized let status_update_dir = target.status_path.join("updates"); - let paths = try!(fs::read_dir(&status_update_dir).map_err( - |e| Error::VcpkgInstallation(format!( + let paths = try!( + fs::read_dir(&status_update_dir).map_err(|e| Error::VcpkgInstallation(format!( "could not read status file updates dir ({}): {}", status_update_dir.display(), e - )) - )); + ))) + ); // get all of the paths of the update files into a Vec let mut paths = try!(paths @@ -1364,6 +1375,13 @@ fn detect_target_triplet() -> Result { lib_suffix: "a".into(), strip_lib_prefix: true, }) + } else if target.starts_with("wasm32-") { + Ok(TargetTriplet { + triplet: "wasm32-emscripten".into(), + is_static: true, + lib_suffix: "a".into(), + strip_lib_prefix: true, + }) } else if !target.contains("-pc-windows-msvc") { Err(Error::NotMSVC) } else if target.starts_with("x86_64-") { @@ -1444,10 +1462,10 @@ mod tests { extern crate tempfile; + use self::tempfile::tempdir; use super::*; use std::env; use std::sync::Mutex; - use self::tempfile::tempdir; lazy_static! { static ref LOCK: Mutex<()> = Mutex::new(()); diff --git a/tests/harfbuzz/build.rs b/tests/harfbuzz/build.rs index 3f4a2cc..b79306e 100644 --- a/tests/harfbuzz/build.rs +++ b/tests/harfbuzz/build.rs @@ -4,12 +4,6 @@ extern crate vcpkg; fn main() { let libs = vcpkg::Config::new().find_package("harfbuzz").unwrap(); - // vcpkg-rs is not capable of working out the correct order to link - // libraries in. This only matters on Linux at present. (vcpkg itself - // does fine, but vcpkg-rs needs to work out how to get the link order - // from the it.) - println!("cargo:rustc-link-lib=brotlicommon-static"); - let mut build = cc::Build::new(); build.file("src/test.c"); for inc in libs.include_paths { diff --git a/tests/wasm.sh b/tests/wasm.sh new file mode 100755 index 0000000..ea39c65 --- /dev/null +++ b/tests/wasm.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -ex + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPTDIR + +TRIPLET=wasm32-emscripten + +export CARGO_BUILD_TARGET=wasm32-unknown-unknown + +export VCPKG_ROOT=$SCRIPTDIR/../vcp + +source ../setup_vcp.sh + +for port in harfbuzz ; do + # check that the port fails before it is installed + $VCPKG_ROOT/vcpkg remove $port:$TRIPLET || true + cargo clean --manifest-path $port/Cargo.toml + cargo build --manifest-path $port/Cargo.toml && exit 2 + echo THIS FAILURE IS EXPECTED + echo This is to ensure that we are not spuriously succeeding because the libraries already exist somewhere on the build machine. + $VCPKG_ROOT/vcpkg install $port:$TRIPLET + cargo build --manifest-path $port/Cargo.toml +done + + +# check manifest mode + +# clean first +cargo clean --manifest-path top-level/Cargo.toml +unset VCPKG_INSTALLED_ROOT +rm -rf $VCPKG_ROOT/installed + +cargo build --manifest-path top-level/Cargo.toml && exit 2 +echo "This failure is expected, as we haven't installed anything from vcpkg yet." + +export VCPKG_INSTALLED_ROOT=$SCRIPTDIR/top-level/vcpkg_installed +pushd top-level +$VCPKG_ROOT/vcpkg install --triplet=$TRIPLET +popd +cargo build --manifest-path top-level/Cargo.toml +unset VCPKG_INSTALLED_ROOT