diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index fe5db93..d8eae51 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -16,33 +16,48 @@ jobs: target: "x86_64-pc-windows-msvc", VCPKG_DEFAULT_TRIPLET: "x64-windows-static", RUSTFLAGS: "-Ctarget-feature=+crt-static", + features: "curl", } - { target: "x86_64-pc-windows-msvc", VCPKG_DEFAULT_TRIPLET: "x64-windows-static-md", + features: "curl", } - { target: "x86_64-pc-windows-msvc", VCPKG_DEFAULT_TRIPLET: "x64-windows", VCPKGRS_DYNAMIC: 1, + features: "curl", } - { target: "i686-pc-windows-msvc", VCPKG_DEFAULT_TRIPLET: "x86-windows-static", RUSTFLAGS: "-Ctarget-feature=+crt-static", + features: "curl", } - { target: "i686-pc-windows-msvc", VCPKG_DEFAULT_TRIPLET: "x86-windows-static-md", + features: "curl", } - { target: "i686-pc-windows-msvc", VCPKG_DEFAULT_TRIPLET: "x86-windows", VCPKGRS_DYNAMIC: 1, + features: "curl", + } + - { + target: "x86_64-pc-windows-gnu", + VCPKG_DEFAULT_TRIPLET: "x64-mingw-static", + } + - { + target: "x86_64-pc-windows-gnu", + VCPKG_DEFAULT_TRIPLET: "x64-mingw-dynamic", + VCPKGRS_DYNAMIC: 1, } fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} @@ -95,8 +110,11 @@ jobs: echo VCPKG_ROOT=${VCPKG_ROOT} echo dyn=${{ matrix.config.VCPKGRS_DYNAMIC }} if [ '${{ matrix.config.VCPKGRS_DYNAMIC }}' != '' ] ; then export VCPKGRS_DYNAMIC=1 ; fi - ${VCPKG_ROOT}/vcpkg.exe install curl zeromq openssl + ${VCPKG_ROOT}/vcpkg.exe install zlib openssl + if [[ '${{ matrix.config.features }}' =~ 'curl' ]]; then + ${VCPKG_ROOT}/vcpkg.exe install curl + fi cargo build --target ${{ matrix.config.target }} --all cargo test --target ${{ matrix.config.target }} --all - cargo run --target ${{ matrix.config.target }} --manifest-path vcpkg_cli/Cargo.toml -- probe curl - cargo run --target ${{ matrix.config.target }} --manifest-path systest/Cargo.toml + cargo run --target ${{ matrix.config.target }} --manifest-path vcpkg_cli/Cargo.toml -- --target ${{ matrix.config.target }} probe zlib + cargo run --target ${{ matrix.config.target }} --manifest-path systest/Cargo.toml --features '${{ matrix.config.features }}' diff --git a/src/lib.rs b/src/lib.rs index b586b96..1d107f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -229,6 +229,9 @@ pub enum Error { /// Could not understand vcpkg installation VcpkgInstallation(String), + /// Unsupported target CPU architecture + UnsupportedArchitecture, + #[doc(hidden)] __Nonexhaustive, } @@ -242,6 +245,7 @@ impl error::Error for Error { Error::VcpkgNotFound(_) => "could not find Vcpkg tree", Error::LibNotFound(_) => "could not find library in Vcpkg tree", Error::VcpkgInstallation(_) => "could not look up details of packages in vcpkg tree", + Error::UnsupportedArchitecture => "target CPU architcture is not supported", Error::__Nonexhaustive => panic!(), } } @@ -261,7 +265,7 @@ impl fmt::Display for Error { Error::RequiredEnvMissing(ref name) => write!(f, "Aborted because {} is not set", name), Error::NotMSVC => write!( f, - "the vcpkg-rs Vcpkg build helper can only find libraries built for the MSVC ABI." + "the vcpkg-rs Vcpkg build helper can only find libraries built for the GNU or MSVC ABI." ), Error::VcpkgNotFound(ref detail) => write!(f, "Could not find Vcpkg tree: {}", detail), Error::LibNotFound(ref detail) => { @@ -272,6 +276,7 @@ impl fmt::Display for Error { "Could not look up details of packages in vcpkg tree {}", detail ), + Error::UnsupportedArchitecture => write!(f, "vcpkg-rs does not support the target CPU architecture."), Error::__Nonexhaustive => panic!(), } } @@ -1364,6 +1369,43 @@ fn detect_target_triplet() -> Result { lib_suffix: "a".into(), strip_lib_prefix: true, }) + } else if target.ends_with("-pc-windows-gnu") { + if target.starts_with("x86_64-") { + if is_definitely_dynamic { + Ok(TargetTriplet { + triplet: "x64-mingw-dynamic".into(), + is_static: false, + lib_suffix: "a".into(), + strip_lib_prefix: true, + }) + } else { + Ok(TargetTriplet { + triplet: "x64-mingw-static".into(), + is_static: true, + lib_suffix: "a".into(), + strip_lib_prefix: true, + }) + } + } else if target.starts_with("i686-") { + if is_definitely_dynamic { + Ok(TargetTriplet { + triplet: "x86-mingw-dynamic".into(), + is_static: false, + lib_suffix: "a".into(), + strip_lib_prefix: true, + }) + } else { + Ok(TargetTriplet { + triplet: "x86-mingw-static".into(), + is_static: true, + lib_suffix: "a".into(), + strip_lib_prefix: true, + }) + } + } else { + // Rust doesn't support aarch64-pc-windows-gnu :( + Err(Error::UnsupportedArchitecture) + } } else if !target.contains("-pc-windows-msvc") { Err(Error::NotMSVC) } else if target.starts_with("x86_64-") { @@ -1457,16 +1499,16 @@ mod tests { fn do_nothing_for_unsupported_target() { let _g = LOCK.lock(); env::set_var("VCPKG_ROOT", "/"); - env::set_var("TARGET", "x86_64-pc-windows-gnu"); + env::set_var("TARGET", "x86_64-pc-windows-invalid"); assert!(match ::probe_package("foo") { Err(Error::NotMSVC) => true, _ => false, }); - env::set_var("TARGET", "x86_64-pc-windows-gnu"); - assert_eq!(env::var("TARGET"), Ok("x86_64-pc-windows-gnu".to_string())); + env::set_var("TARGET", "aarch64-pc-windows-gnu"); + assert_eq!(env::var("TARGET"), Ok("aarch64-pc-windows-gnu".to_string())); assert!(match ::probe_package("foo") { - Err(Error::NotMSVC) => true, + Err(Error::UnsupportedArchitecture) => true, _ => false, }); env::remove_var("TARGET"); @@ -1598,6 +1640,8 @@ mod tests { for target in &[ "x86_64-apple-darwin", "i686-pc-windows-msvc", + // TODO: add test data for platforms + // "x86_64-pc-windows-gnu", // "x86_64-pc-windows-msvc", // "x86_64-unknown-linux-gnu", ] { diff --git a/systest/Cargo.toml b/systest/Cargo.toml index 3798ecb..a475779 100644 --- a/systest/Cargo.toml +++ b/systest/Cargo.toml @@ -4,13 +4,14 @@ version = "0.1.0" authors = ["Jim McGrath "] [features] +curl=["dep:curl"] extras=["zmq-sys"] [dependencies] # using * for the dependency version is appropriate here since # the purpose of this project is to fail in CI if the latest # versions do not build -curl = "*" +curl = { version = "*", optional = true } libz-sys = "*" openssl-sys = "*" zmq-sys = { git = "https://github.com/mcgoo/rust-zmq", branch = "vcpkg", optional=true } diff --git a/systest/src/main.rs b/systest/src/main.rs index 64a2910..75935d9 100644 --- a/systest/src/main.rs +++ b/systest/src/main.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "curl")] extern crate curl; extern crate libz_sys; extern crate openssl_sys; @@ -8,7 +9,10 @@ extern crate zmq_sys; use std::ffi::CStr; fn main() { + #[cfg(feature = "curl")] println!("curl version is {:?}!", curl::Version::get().version()); + #[cfg(not(feature = "curl"))] + println!("curl test disabled in this build!"); unsafe { println!( @@ -17,9 +21,13 @@ fn main() { ); } - //unsafe{ println!("openssl version is {:?}!", CStr::from_ptr(openssl_sys::SSLEAY_VERSION));} openssl_sys::init(); - // println!("openssl version is {}!", openssl_sys::OPENSSL_VERSION); + unsafe { + println!( + "openssl version is {:?}!", + CStr::from_ptr(openssl_sys::OpenSSL_version(openssl_sys::OPENSSL_VERSION)) + ); + } // unsafe {let ctx = zmq_sys::zmq_init(1); }