Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion livekit-ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ fn main() {
}

let webrtc_dir = webrtc_sys_build::webrtc_dir();
println!("cargo:warning=livekit-ffi downloading webrtc to {webrtc_dir:?}");
webrtc_sys_build::download_webrtc().unwrap();
if !webrtc_dir.exists() {
webrtc_sys_build::download_webrtc().unwrap();
panic!("download_webrtc didn't create webrtc_dir")
}

{
Expand Down
4 changes: 3 additions & 1 deletion webrtc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ fn main() {
let webrtc_include = webrtc_dir.join("include");
let webrtc_lib = webrtc_dir.join("lib");

println!("cargo:warning=webrtc-sys downloading webrtc to {webrtc_dir:?}");
webrtc_sys_build::download_webrtc().unwrap();
if !webrtc_dir.exists() {
webrtc_sys_build::download_webrtc().unwrap();
panic!("download_webrtc didn't create webrtc_dir")
}

builder.includes(&[
Expand Down
2 changes: 0 additions & 2 deletions webrtc-sys/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ regex = "1.0"
scratch = "1.0"
fs2 = "0.4"
semver = "1.0"
sha2 = "0.10"
hex-literal = "1.0.0"
62 changes: 5 additions & 57 deletions webrtc-sys/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

use std::{
collections::HashMap,
env,
error::Error,
fs::{self, File},
Expand All @@ -23,10 +22,8 @@ use std::{
};

use fs2::FileExt;
use hex_literal::hex;
use regex::Regex;
use reqwest::StatusCode;
use sha2::{Digest as _, Sha256};

pub const SCRATH_PATH: &str = "livekit_webrtc";
pub const WEBRTC_TAG: &str = "webrtc-b99fd2c-6";
Expand Down Expand Up @@ -87,8 +84,7 @@ pub fn custom_dir() -> Option<path::PathBuf> {

/// Location of the downloaded webrtc binaries
pub fn prebuilt_dir() -> path::PathBuf {
let target_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
path::Path::new(&target_dir).join(format!(
PathBuf::from(std::env::var("OUT_DIR").unwrap()).join(format!(
"livekit/{}-{}/{}",
webrtc_triple(),
WEBRTC_TAG,
Expand Down Expand Up @@ -136,8 +132,6 @@ pub fn webrtc_defines() -> Vec<(String, Option<String>)> {
}

pub fn configure_jni_symbols() -> Result<(), Box<dyn Error>> {
download_webrtc()?;

let toolchain = android_ndk_toolchain()?;
let toolchain_bin = toolchain.join("bin");

Expand Down Expand Up @@ -180,69 +174,23 @@ pub fn configure_jni_symbols() -> Result<(), Box<dyn Error>> {
}

pub fn download_webrtc() -> Result<(), Box<dyn Error>> {
let dir = scratch::path(SCRATH_PATH);
let flock = File::create(dir.join(".lock"))?;
flock.lock_exclusive()?;

let webrtc_dir = webrtc_dir();
if webrtc_dir.exists() {
return Ok(());
}
std::fs::remove_dir_all(&webrtc_dir).ok();

let mut resp = reqwest::blocking::get(download_url())?;
if resp.status() != StatusCode::OK {
return Err(format!("failed to download webrtc: {}", resp.status()).into());
}

let digests = [
(
"linux-arm64-release",
hex!("363d90ed91ffc8fc70c94ad86759876a3255d526ac0792fbf9e9462cac964b81"),
),
(
"linux-x64-release",
hex!("130b37ae8d3ffcdff8ed9347cb482a493075b586cbfaa9ebe1f0079ddb734ff1"),
),
(
"mac-arm64-release",
hex!("b29fed70cfa8282fce1e987b3abf9a471b5d223ddcf03f64282f8d5f0cc89542"),
),
(
"mac-x64-release",
hex!("3f24dc470977d976aa3b72add36dec6822f1da65031b493a67645af1e7aca792"),
),
(
"win-arm64-release",
hex!("69bafa396c4032b06468c396da6a05a431761631f47a1e5d1e8a2cc6c3dd6fe9"),
),
(
"win-x64-release",
hex!("eb7dcc30bc7c3f331acd8648495b420e7f2445f5d8d49ddb755026b2b572495d"),
),
]
.into_iter()
.collect::<HashMap<_, _>>();

let tmp_path = env::var("OUT_DIR").unwrap() + "/webrtc.zip";
let tmp_path = path::Path::new(&tmp_path);
let mut file =
fs::File::options().write(true).read(true).create(true).truncate(true).open(tmp_path)?;
resp.copy_to(&mut file)?;
let content = std::fs::read(tmp_path)?;
let digest = Sha256::digest(&content);
if digest.as_slice() != digests[webrtc_triple().as_str()].as_slice() {
return Err("corrupt webrtc download".to_owned().into());
}

let result = (|| {
let mut archive = zip::ZipArchive::new(file)?;
archive.extract(webrtc_dir.parent().unwrap())?;
Ok::<_, Box<dyn Error>>(())
})();
if result.is_err() {
std::fs::remove_dir_all(webrtc_dir).ok();
}
result?;
let mut archive = zip::ZipArchive::new(file)?;
archive.extract(webrtc_dir.parent().unwrap())?;
drop(archive);

Ok(())
}
Expand Down
Loading