Skip to content

Commit

Permalink
fix build in windows msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLocal committed Jun 25, 2024
1 parent b5f9444 commit 9e71409
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ license = "MIT"
readme = "README.md"

[dependencies]
rszlm-sys = { path = "./rszlm-sys" }
rszlm-sys = { path = "rszlm-sys" }
once_cell = "1.8"
anyhow = "1"

[dev-dependencies]
rszlm = { path = "./", features = ["static", "webrtc"] }
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7", features = ["full"] }

Expand Down
2 changes: 0 additions & 2 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rszlm::{
init::EnvInitBuilder,
player::ProxyPlayerBuilder,
server::{http_server_start, rtmp_server_start, rtsp_server_start, stop_all_server},
webrtc::rtc_server_start,
};
use tokio::sync::RwLock;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -185,7 +184,6 @@ fn start_zlm_background(
http_server_start(8553, false);
rtsp_server_start(8554, false);
rtmp_server_start(8555, false);
rtc_server_start(8556);
{
let mut events = EVENTS.write().unwrap();
let tx_clone = tx.clone();
Expand Down
29 changes: 18 additions & 11 deletions rszlm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ fn build() -> io::Result<()> {
cmake
.uses_cxx11()
.profile("Release")
.out_dir(&src_install_path())
.very_verbose(true);
.out_dir(&src_install_path());

if is_static() {
cmake.define("ENABLE_API_STATIC_LIB", "ON");
cmake.define("OPENSSL_USE_STATIC_LIBS", "ON");
}

#[cfg(feature = "webrtc")]
cmake.define("ENABLE_WEBRTC", "ON");
#[cfg(not(feature = "webrtc"))]
cmake.define("ENABLE_WEBRTC", "OFF");

cmake.register_dep("openssl-sys");
cmake.register_dep("OPENSSL");

let dst = cmake.build();
println!("dst: {}", dst.to_string_lossy());
println!("cargo:root={}", dst.to_string_lossy());
std::fs::read_dir(src_path().join(zlm_release_path()))?
.into_iter()
.for_each(|e| {
Expand All @@ -114,8 +114,8 @@ fn build() -> io::Result<()> {
Ok(())
}

fn link_dynamic() {
println!("cargo:rustc-link-lib=mk_api");
fn link_dynamic(_zlm_link_path: &PathBuf) {
println!("cargo:rustc-link-lib=dylib=mk_api");
}

fn link_static(zlm_link_path: &PathBuf) {
Expand Down Expand Up @@ -199,7 +199,7 @@ fn buildgen() {
if is_static {
link_static(&zlm_install_lib);
} else {
link_dynamic();
link_dynamic(&zlm_install_lib);
}

// generate bindings
Expand Down Expand Up @@ -239,26 +239,33 @@ fn find_libsrtp2() {

#[allow(dead_code)]
fn build_srtp() {
let git_url = if env::var("ZLM_GIT_ZONE") == Ok("gitee".to_string()) {
"https://gitee.com/mirrors/libsrtp.git".to_string()
} else {
"https://github.com/cisco/libsrtp.git".to_string()
};

// download from github
if !&out_dir().join("libsrtp").exists() {
Command::new("git")
.arg("clone")
.arg("-b")
.arg("v2.3.0")
.arg("https://github.com/cisco/libsrtp.git")
.arg(git_url)
.current_dir(&out_dir())
.status()
.unwrap();
}

println!("env: {:?}", env::vars());

// build srtp
let mut cmake = cmake::Config::new(&out_dir().join("libsrtp"));
cmake
.profile("Release")
.define("ENABLE_OPENSSL", "ON")
//.define("ENABLE_OPENSSL", "ON")
.out_dir(&out_dir().join("srtp-install"))
.register_dep("openssl-sys")
.very_verbose(true);
.register_dep("OPENSSL");

cmake.build();
println!(
Expand Down
16 changes: 16 additions & 0 deletions src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ pub enum CodecId {
H265,
}

/// i do not why
/// in msvc, 0 is H264, 1 is H265
/// unsafe { MKCodecH264 } will build error with:
/// error LNK2019: unresolved external symbol MKCodecH264
/// error LNK2019: unresolved external symbol MKCodecH265
#[cfg(target_env = "msvc")]
impl Into<i32> for CodecId {
fn into(self) -> i32 {
match self {
CodecId::H264 => 0,
CodecId::H265 => 1,
}
}
}

#[cfg(not(target_env = "msvc"))]
impl Into<i32> for CodecId {
fn into(self) -> i32 {
match self {
Expand Down

0 comments on commit 9e71409

Please sign in to comment.