提交 ff4108bf authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Windows support in Rust library

上级 f0ebd809
...@@ -12,6 +12,7 @@ jobs: ...@@ -12,6 +12,7 @@ jobs:
os: os:
- ubuntu-20.04 - ubuntu-20.04
- macos-10.15 - macos-10.15
- windows-2019
rust: rust:
- stable - stable
# - nightly # - nightly
...@@ -19,6 +20,17 @@ jobs: ...@@ -19,6 +20,17 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Add MSVC compiler
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
# This is needed as a workaround for GNU linker being first in PATH and thus preventing Meson from finding MSVC
# linker.
- name: Remove GNU linker for MSVC
shell: bash
run: rm /usr/bin/link
if: runner.os == 'Windows'
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Switch from file descriptors to function calls when communicating with worker * Switch from file descriptors to function calls when communicating with worker
* Various optimizations that caused minor breaking changes to public API * Various optimizations that caused minor breaking changes to public API
* Requests no longer have internal timeout, but they can now be cancelled, add your own timeouts on top if needed * Requests no longer have internal timeout, but they can now be cancelled, add your own timeouts on top if needed
* Windows support
# 0.8.5 # 0.8.5
......
...@@ -7,7 +7,9 @@ fn main() { ...@@ -7,7 +7,9 @@ fn main() {
return; return;
} }
let build_type = if cfg!(debug_assertions) { // On Windows Rust always links against release version of MSVC runtime, thus requires Release
// build here.
let build_type = if cfg!(all(debug_assertions, not(windows))) {
"Debug" "Debug"
} else { } else {
"Release" "Release"
...@@ -73,19 +75,15 @@ fn main() { ...@@ -73,19 +75,15 @@ fn main() {
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
panic!("Building on Windows is not currently supported"); // Nothing special is needed so far
// TODO: Didn't bother, feel free to PR
} }
// The build here is a bit awkward since we can't just specify custom target directory as
// openssl will fail to build with `make[1]: /bin/sh: Argument list too long` due to large
// number of files. So instead we build in place, copy files to out directory and then clean
// after ourselves
{ {
// Build // Build
if !Command::new("make") if !Command::new("make")
.arg("libmediasoup-worker") .arg("libmediasoup-worker")
.env("MEDIASOUP_OUT_DIR", &out_dir) // Force forward slashes on Windows too so that is plays well with our dumb `Makefile`
.env("MEDIASOUP_OUT_DIR", &out_dir.replace('\\', "/"))
.env("MEDIASOUP_BUILDTYPE", &build_type) .env("MEDIASOUP_BUILDTYPE", &build_type)
.spawn() .spawn()
.expect("Failed to start") .expect("Failed to start")
...@@ -111,6 +109,37 @@ fn main() { ...@@ -111,6 +109,37 @@ fn main() {
} }
} }
#[cfg(target_os = "windows")]
{
let dot_a = format!("{}/{}/libmediasoup-worker.a", out_dir, build_type);
let dot_lib = format!("{}/{}/mediasoup-worker.lib", out_dir, build_type);
// Meson builds `libmediasoup-worker.a` on Windows instead of `*.lib` file under MinGW
if std::path::Path::new(&dot_a).exists() {
std::fs::copy(&dot_a, &dot_lib).unwrap_or_else(|_| {
panic!(
"Failed to copy static library from {} to {}",
dot_a, dot_lib,
)
});
}
// These are required by libuv on Windows
println!("cargo:rustc-link-lib=psapi");
println!("cargo:rustc-link-lib=user32");
println!("cargo:rustc-link-lib=advapi32");
println!("cargo:rustc-link-lib=iphlpapi");
println!("cargo:rustc-link-lib=userenv");
println!("cargo:rustc-link-lib=ws2_32");
// These are required by OpenSSL on Windows
println!("cargo:rustc-link-lib=ws2_32");
println!("cargo:rustc-link-lib=gdi32");
println!("cargo:rustc-link-lib=advapi32");
println!("cargo:rustc-link-lib=crypt32");
println!("cargo:rustc-link-lib=user32");
}
println!("cargo:rustc-link-lib=static=mediasoup-worker"); println!("cargo:rustc-link-lib=static=mediasoup-worker");
println!("cargo:rustc-link-search=native={}/{}", out_dir, build_type); println!("cargo:rustc-link-search=native={}/{}", out_dir, build_type);
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论