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

Add support for mingw (-pc-windows-gnu) targets #52

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
26 changes: 22 additions & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
Expand Down Expand Up @@ -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 }}'
54 changes: 49 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ pub enum Error {
/// Could not understand vcpkg installation
VcpkgInstallation(String),

/// Unsupported target CPU architecture
UnsupportedArchitecture,

#[doc(hidden)]
__Nonexhaustive,
}
Expand All @@ -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!(),
}
}
Expand All @@ -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) => {
Expand All @@ -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!(),
}
}
Expand Down Expand Up @@ -1364,6 +1369,43 @@ fn detect_target_triplet() -> Result<TargetTriplet, Error> {
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-") {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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",
] {
Expand Down
3 changes: 2 additions & 1 deletion systest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ version = "0.1.0"
authors = ["Jim McGrath <[email protected]>"]

[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 }
Expand Down
12 changes: 10 additions & 2 deletions systest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "curl")]
extern crate curl;
extern crate libz_sys;
extern crate openssl_sys;
Expand All @@ -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!(
Expand All @@ -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); }

Expand Down