Skip to content

Commit

Permalink
Windowsビルドの安定化 (#95)
Browse files Browse the repository at this point in the history
* b25-sysのbuild.rsを整理

* rcでのCI有効化
  • Loading branch information
kazuki0824 authored Nov 11, 2023
1 parent 525fd1f commit 4b41438
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 87 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches:
- 'master'
- 'release-candidates/**'
workflow_dispatch:

env:
Expand Down Expand Up @@ -115,5 +117,4 @@ jobs:
- name: Run tests(MinGW)
shell: msys2 {0}
if: endsWith(matrix.toolchain, 'gnu')
continue-on-error: true
run: export PATH=$PATH:/c/Users/runneradmin/.cargo/bin && cargo test --workspace --verbose
126 changes: 47 additions & 79 deletions b25-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,97 +1,65 @@
extern crate pkg_config;

#[allow(unused_must_use)]
#[allow(clippy::overly_complex_bool_expr)]
#[allow(clippy::nonminimal_bool)]
fn main() {
// let out_dir = env::var("OUT_DIR").unwrap();
// let out_path = PathBuf::from(&out_dir);
// let include_dir = format!("{}/{}", out_dir, "include");

let pc = pkg_config::Config::new();

//If libaribb25 is found, then it'll continue. If not found, start build & deployment.
pc.probe("libpcsclite");

if pc.target_supported() && cfg!(target_os = "linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
if !pc.probe("libaribb25").is_err() {
// Staticaly link against libaribb25.so or aribb25.lib.
println!("cargo:rustc-link-lib=static=aribb25");
return;
}
//start self build in Linux
}

fn prep_cmake() -> cmake::Config {
let mut cm = cmake::Config::new("./externals/libaribb25");
cm.very_verbose(true);

// Enable AVX2 for x64
// NEON SIMD is also supported, but not all ARM SoCs support it, so build without it.
if cfg!(target_arch = "x86_64") {
cm.configure_arg("-DUSE_AVX2=ON");
}

if cfg!(target_os = "windows") {
if cfg!(target_env = "msvc") {
cm.generator("Visual Studio 17 2022");
/*
MSVC + libaribb25(debug) = fail
warning LNK4098: defaultlib \'MSVCRTD.../NODEFAULTLIB:library...
*/
cm.profile("Release");
} else if cfg!(target_env = "gnu") {
match std::env::var("MSYSTEM") {
Ok(sys_name) if sys_name.to_lowercase().contains("mingw64") => {
cm.generator("Ninja");
#[cfg(debug_assertions)]
println!("cargo:rustc-link-lib=msvcrtd");
#[cfg(not(debug_assertions))]
println!("cargo:rustc-link-lib=msvcrt");
println!("cargo:rustc-link-lib=ucrtbase");
}
Ok(sys_name) => {
panic!("target_env:={sys_name} not supported.")
}
_ => {
// TODO
cm.generator("MinGW Makefiles");
#[cfg(debug_assertions)]
println!("cargo:rustc-link-lib=msvcrtd");
#[cfg(not(debug_assertions))]
println!("cargo:rustc-link-lib=msvcrt");
println!("cargo:rustc-link-lib=ucrtbase");
}
if cfg!(windows) {
if cfg!(target_env = "gnullvm") {
unimplemented!("tier3 gnullvm")
}
match (cfg!(target_env = "gnu"), std::env::var("MSYSTEM")) {
(false, _) => {
cm.generator("Visual Studio 17 2022");
}
(true, Ok(sys_name)) if sys_name.to_lowercase().contains("mingw") => {
cm.generator("Ninja");
}
(true, Ok(sys_name)) if sys_name.to_lowercase().contains("ucrt") => {
cm.generator("Ninja");
}
(true, Ok(sys_name)) => {
panic!("target_env:={sys_name} not supported.")
}
} else if cfg!(target_env = "gnullvm") {
match std::env::var("MSYSTEM") {
Ok(sys_name) if sys_name.to_lowercase().contains("ucrt") => {
cm.generator("Ninja");
println!("cargo:rustc-link-lib=ucrt");
}
Ok(sys_name) if sys_name.to_lowercase().contains("clang") => {
cm.generator("Ninja");
println!("cargo:rustc-link-lib=ucrt");
}
Ok(sys_name) => {
panic!("target_env:={sys_name} not supported.")
}
_ => {
// TODO
cm.generator("MinGW Makefiles");
println!("cargo:rustc-link-lib=ucrt");
// println!("cargo:rustc-link-lib=vcruntime140");
}
(true, _) => {
cm.generator("MinGW Makefiles");
}
// llvm-mingw
}
println!("cargo:rustc-link-search=native=C:\\Windows\\System32");
println!("cargo:rustc-link-lib=dylib=winscard");
}

let res = cm.build();
println!("cargo:rustc-link-search=native={}/lib", res.display());
println!("cargo:rustc-link-search=native={}/lib64", res.display());

// Staticaly link against libaribb25.so or aribb25.lib.
println!("cargo:rustc-link-lib=static=aribb25");

#[cfg(debug_assertions)]
cm.profile("Debug");
#[cfg(not(debug_assertions))]
cm.profile("Release");

cm
}

fn main() {
let pc = pkg_config::Config::new();
if cfg!(windows) {
let res = prep_cmake().build();
println!("cargo:rustc-link-search=native={}/lib", res.display());
println!("cargo:rustc-link-lib=dylib=winscard");
} else if cfg!(target_os = "linux") {
if pc.probe("libpcsclite").is_err() {
panic!()
}
if pc.probe("libaribb25").is_err() {
// Staticaly link against libaribb25.so or aribb25.lib.
} else {
let res = prep_cmake().build();
println!("cargo:rustc-link-search=native={}/lib", res.display());
println!("cargo:rustc-link-search=native={}/lib64", res.display());
}
}
}
18 changes: 12 additions & 6 deletions recisdb-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,31 @@ clap-num = "1"
colored = "^2.0.0"
cpp_utils = "0.3.0"
ctrlc = { version = "^3.0", features = ["termination"] }
dvbv5 = { version = "0.2.6", optional = true }
dvbv5-sys = { version = "*", optional = true }
env_logger = "^0.10.0"
futures-executor = "0.3.26"
futures-time = "3.0.0"
futures-util = { version = "0.3.26", features = ["io"], default-features = false }
indicatif = "0.17"
libloading = "^0.8.0"
log = "^0.4.17"
nix = { version = "^0.27.1", features = ["ioctl"] }
nom = "7.1.3"
pin-project-lite = "0.2.9"

[build-dependencies]
bindgen = { version = "0.68.1", default_features = false }
cargo-deb = "2.0.0"
cc = "1.0.70"
cc = { version = "1.0", features = ["parallel"] }
glob = "0.3"

[target.'cfg(windows)'.dependencies]
libloading = "^0.8.0"

[target.'cfg(unix)'.dependencies]
dvbv5 = { version = "0.2.6", optional = true }
dvbv5-sys = { version = "*", optional = true }
nix = { version = "^0.27.1", features = ["ioctl"] }

[target.'cfg(unix)'.build-dependencies]
cargo-deb = "2.0.0"

[package.metadata.deb]
maintainer = "Kazuki Kuroda <maleicacid824+dev@gmail.com>"
copyright = "2021-2022, Kazuki Kuroda <maleicacid824+dev@gmail.com>"
Expand Down

0 comments on commit 4b41438

Please sign in to comment.