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
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'tests/**'
- 'Cargo.toml'
- 'opus/**/*'
- 'build.rs'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
Expand All @@ -20,6 +21,7 @@ on:
- 'tests/**'
- 'Cargo.toml'
- 'opus/**/*'
- 'build.rs'
jobs:
check:
strategy:
Expand Down
26 changes: 25 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,29 @@ fn set_cmake_define_if_present(config: &mut cmake::Config, name: &str) {
fn build() {
const CURRENT_DIR: &str = "opus";

//Disable LTO if someone tries to force it (e.g. Arch makepkg)
//This is necessary because cmake crate doesn't pass env variables at configure step, so we will
//adjust both configure variables and general build env (just in case)
fn fix_build_env(cmake: &mut cmake::Config) {
for (var, cmake_var) in [("CFLAGS", "CMAKE_C_FLAGS"), ("CXXFLAGS", "CMAKE_CXX_FLAGS")] {
if let Ok(value) = std::env::var(var) {
if value.contains("-flto") {
println!("cargo:warning=env::{var} contains LTO option. Overriding it...");
let filtered: String = value
.split_whitespace()
.filter(|f| !f.starts_with("-flto"))
.collect::<Vec<_>>()
.join(" ");
cmake
.configure_arg(format!("-D{cmake_var}={filtered}"))
.env(var, filtered);
}
}
}
}

let mut cmake = cmake::Config::new(CURRENT_DIR);
fix_build_env(&mut cmake);
cmake.define("OPUS_INSTALL_PKG_CONFIG_MODULE", "OFF")
.define("OPUS_INSTALL_CMAKE_CONFIG_MODULE", "OFF")
//Defining these variables disable GNUInstallDirs so in addition to /lib
Expand All @@ -100,7 +122,9 @@ fn build() {
.define("CMAKE_INSTALL_INCLUDEDIR", "include")
.define("CMAKE_INSTALL_OLDINCLUDEDIR", "include")
.define("CMAKE_INSTALL_LIBDIR", "lib")
.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY");
.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY")
//Ensure opus's CMake never enables LTO
.define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "off");

//Keep this up to date with Cargo.toml
if cfg!(feature = "dred") {
Expand Down
14 changes: 13 additions & 1 deletion tests/version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use opusic_sys::opus_get_version_string;
use opusic_sys::{opus_get_version_string, opus_decoder_create, opus_decoder_destroy};

use core::ptr;
use core::ffi::CStr;

#[test]
Expand All @@ -10,3 +11,14 @@ fn check_version() {
let version = version.to_str().expect("utf-8 string");
assert_eq!("libopus 1.6.1", version);
}

#[test]
fn check_decoder_symbols() {
let result = unsafe {
opus_decoder_create(8000, 2, ptr::null_mut())
};
assert!(!result.is_null());
unsafe {
opus_decoder_destroy(result);
}
}
Loading