summaryrefslogtreecommitdiffstats
path: root/third_party/rust/coreaudio-sys
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/coreaudio-sys
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/coreaudio-sys')
-rw-r--r--third_party/rust/coreaudio-sys/.cargo-checksum.json1
-rw-r--r--third_party/rust/coreaudio-sys/Cargo.toml55
-rw-r--r--third_party/rust/coreaudio-sys/LICENSE25
-rw-r--r--third_party/rust/coreaudio-sys/README.md19
-rw-r--r--third_party/rust/coreaudio-sys/build.rs166
-rw-r--r--third_party/rust/coreaudio-sys/src/lib.rs6
6 files changed, 272 insertions, 0 deletions
diff --git a/third_party/rust/coreaudio-sys/.cargo-checksum.json b/third_party/rust/coreaudio-sys/.cargo-checksum.json
new file mode 100644
index 0000000000..61ca470aee
--- /dev/null
+++ b/third_party/rust/coreaudio-sys/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"9b1fbf81f247b3c533da2496ffd66035c19bd8bbd6ea2a3edf1bd227440d2535","LICENSE":"7576269ea71f767b99297934c0b2367532690f8c4badc695edf8e04ab6a1e545","README.md":"a8adeaf1947035175b890109b36604ac3676f887911b5b8debd216689c0b65bd","build.rs":"e3d45b1a17b655996a09b1d8f5f4dabb8c574e5b803814a13494f56dfce32f4e","src/lib.rs":"22c9dbbb1dc38d6f77b9362e806a7ee59a8ca1aa9b2c9344d1a487a91287ed59"},"package":"f034b2258e6c4ade2f73bf87b21047567fb913ee9550837c2316d139b0262b24"} \ No newline at end of file
diff --git a/third_party/rust/coreaudio-sys/Cargo.toml b/third_party/rust/coreaudio-sys/Cargo.toml
new file mode 100644
index 0000000000..8a339dbbef
--- /dev/null
+++ b/third_party/rust/coreaudio-sys/Cargo.toml
@@ -0,0 +1,55 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+name = "coreaudio-sys"
+version = "0.2.12"
+authors = ["Mitchell Nordine <mitchell.nordine@gmail.com>"]
+build = "build.rs"
+description = "Bindings for Apple's CoreAudio frameworks generated via rust-bindgen"
+homepage = "https://github.com/RustAudio/coreaudio-sys"
+readme = "README.md"
+keywords = [
+ "core",
+ "audio",
+ "unit",
+ "osx",
+ "ios",
+]
+license = "MIT"
+repository = "https://github.com/RustAudio/coreaudio-sys.git"
+
+[package.metadata.docs.rs]
+all-features = true
+default-target = "x86_64-apple-darwin"
+targets = [
+ "x86_64-apple-darwin",
+ "x86_64-apple-ios",
+]
+
+[build-dependencies.bindgen]
+version = "0.64"
+features = ["runtime"]
+default-features = false
+
+[features]
+audio_toolbox = []
+audio_unit = []
+core_audio = []
+core_midi = []
+default = [
+ "audio_toolbox",
+ "audio_unit",
+ "core_audio",
+ "open_al",
+ "core_midi",
+]
+open_al = []
diff --git a/third_party/rust/coreaudio-sys/LICENSE b/third_party/rust/coreaudio-sys/LICENSE
new file mode 100644
index 0000000000..9203baa055
--- /dev/null
+++ b/third_party/rust/coreaudio-sys/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2015
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/third_party/rust/coreaudio-sys/README.md b/third_party/rust/coreaudio-sys/README.md
new file mode 100644
index 0000000000..e6cacf3ac3
--- /dev/null
+++ b/third_party/rust/coreaudio-sys/README.md
@@ -0,0 +1,19 @@
+# coreaudio-sys [![Actions Status](https://github.com/rustaudio/coreaudio-sys/workflows/coreaudio-sys/badge.svg)](https://github.com/rustaudio/coreaudio-sys/actions) [![Crates.io](https://img.shields.io/crates/v/coreaudio-sys.svg)](https://crates.io/crates/coreaudio-sys) [![Crates.io](https://img.shields.io/crates/l/coreaudio-sys.svg)](https://github.com/RustAudio/coreaudio-sys/blob/master/LICENSE) [![docs.rs](https://docs.rs/coreaudio-sys/badge.svg)](https://docs.rs/coreaudio-sys/)
+
+Raw bindings to Apple's Core Audio API for macos and iOS generated using [rust-bindgen](https://github.com/rust-lang-nursery/rust-bindgen). [coreaudio-rs](https://github.com/RustAudio/coreaudio-rs) is an attempt at offering a higher level API around this crate.
+
+## Cross Compiling
+
+[Rust Cross](https://github.com/japaric/rust-cross) has a good explanation of how cross-compiling Rust works in general. While the author of Rust Cross advises against it, it is perfectly possible to cross-compile Rust for MacOS on Linux. [OSXCross](https://github.com/tpoechtrager/osxcross) can be used to create a compiler toolchain that can compile for MacOS on Linux.
+
+### Environment Variables
+
+When cross-compiling for MacOS on Linux there are two environment variables that are used to configure how `coreaudio-sys` finds the required headers and libraries. The following examples assume that you have OSXCross installed at `/build/osxcross`.
+
+#### `COREAUDIO_SDK_PATH`
+
+This tell `coreaudio-sys` where to find the MacOS SDK:
+
+```bash
+export COREAUDIO_SDK_PATH=/build/osxcross/target/SDK/MacOSX10.11.sdk
+```
diff --git a/third_party/rust/coreaudio-sys/build.rs b/third_party/rust/coreaudio-sys/build.rs
new file mode 100644
index 0000000000..81cfbcc855
--- /dev/null
+++ b/third_party/rust/coreaudio-sys/build.rs
@@ -0,0 +1,166 @@
+extern crate bindgen;
+
+fn sdk_path(target: &str) -> Result<String, std::io::Error> {
+ // Use environment variable if set
+ println!("cargo:rerun-if-env-changed=COREAUDIO_SDK_PATH");
+ if let Ok(path) = std::env::var("COREAUDIO_SDK_PATH") {
+ return Ok(path);
+ }
+
+ use std::process::Command;
+
+ let sdk = if target.contains("apple-darwin") {
+ "macosx"
+ } else if target == "x86_64-apple-ios"
+ || target == "i386-apple-ios"
+ || target == "aarch64-apple-ios-sim"
+ {
+ "iphonesimulator"
+ } else if target == "aarch64-apple-ios"
+ || target == "armv7-apple-ios"
+ || target == "armv7s-apple-ios"
+ {
+ "iphoneos"
+ } else {
+ unreachable!();
+ };
+ let output = Command::new("xcrun")
+ .args(&["--sdk", sdk, "--show-sdk-path"])
+ .output()?
+ .stdout;
+ let prefix_str = std::str::from_utf8(&output).expect("invalid output from `xcrun`");
+ Ok(prefix_str.trim_end().to_string())
+}
+
+fn build(sdk_path: Option<&str>, target: &str) {
+ // Generate one large set of bindings for all frameworks.
+ //
+ // We do this rather than generating a module per framework as some frameworks depend on other
+ // frameworks and in turn share types. To ensure all types are compatible across each
+ // framework, we feed all headers to bindgen at once.
+ //
+ // Only link to each framework and include their headers if their features are enabled and they
+ // are available on the target os.
+
+ use std::env;
+ use std::path::PathBuf;
+
+ let mut headers: Vec<&'static str> = vec![];
+
+ #[cfg(feature = "audio_unit")]
+ {
+ // Since iOS 10.0 and macOS 10.12, all the functionality in AudioUnit
+ // moved to AudioToolbox, and the AudioUnit headers have been simple
+ // wrappers ever since.
+ if target.contains("apple-ios") {
+ // On iOS, the AudioUnit framework does not have (and never had) an
+ // actual dylib to link to, it is just a few header files.
+ // The AudioToolbox framework contains the symbols instead.
+ println!("cargo:rustc-link-lib=framework=AudioToolbox");
+ } else {
+ // On macOS, the symbols are present in the AudioToolbox framework,
+ // but only on macOS 10.12 and above.
+ //
+ // However, unlike on iOS, the AudioUnit framework on macOS
+ // contains a dylib with the desired symbols, that we can link to
+ // (in later versions just re-exports from AudioToolbox).
+ println!("cargo:rustc-link-lib=framework=AudioUnit");
+ }
+ headers.push("AudioUnit/AudioUnit.h");
+ }
+
+ #[cfg(feature = "audio_toolbox")]
+ {
+ println!("cargo:rustc-link-lib=framework=AudioToolbox");
+ headers.push("AudioToolbox/AudioToolbox.h");
+ }
+
+ #[cfg(feature = "core_audio")]
+ {
+ println!("cargo:rustc-link-lib=framework=CoreAudio");
+
+ if target.contains("apple-ios") {
+ headers.push("CoreAudio/CoreAudioTypes.h");
+ } else {
+ headers.push("CoreAudio/CoreAudio.h");
+ }
+ }
+
+ #[cfg(feature = "open_al")]
+ {
+ println!("cargo:rustc-link-lib=framework=OpenAL");
+ headers.push("OpenAL/al.h");
+ headers.push("OpenAL/alc.h");
+ }
+
+ #[cfg(all(feature = "core_midi"))]
+ {
+ if target.contains("apple-darwin") {
+ println!("cargo:rustc-link-lib=framework=CoreMIDI");
+ headers.push("CoreMIDI/CoreMIDI.h");
+ }
+ }
+
+ println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
+ // Get the cargo out directory.
+ let out_dir = PathBuf::from(env::var("OUT_DIR").expect("env variable OUT_DIR not found"));
+
+ // Begin building the bindgen params.
+ let mut builder = bindgen::Builder::default();
+
+ // See https://github.com/rust-lang/rust-bindgen/issues/1211
+ // Technically according to the llvm mailing list, the argument to clang here should be
+ // -arch arm64 but it looks cleaner to just change the target.
+ let target = if target == "aarch64-apple-ios" {
+ "arm64-apple-ios"
+ } else if target == "aarch64-apple-darwin" {
+ "arm64-apple-darwin"
+ } else {
+ target
+ };
+ builder = builder.size_t_is_usize(true);
+
+ builder = builder.clang_args(&[&format!("--target={}", target)]);
+
+ if let Some(sdk_path) = sdk_path {
+ builder = builder.clang_args(&["-isysroot", sdk_path]);
+ }
+ if target.contains("apple-ios") {
+ // time.h as has a variable called timezone that conflicts with some of the objective-c
+ // calls from NSCalendar.h in the Foundation framework. This removes that one variable.
+ builder = builder.blocklist_item("timezone");
+ builder = builder.blocklist_item("objc_object");
+ }
+
+ // bindgen produces alignment tests that cause undefined behavior in some cases.
+ // This seems to happen across all apple target tripples :/.
+ // https://github.com/rust-lang/rust-bindgen/issues/1651
+ builder = builder.layout_tests(false);
+
+ let meta_header: Vec<_> = headers
+ .iter()
+ .map(|h| format!("#include <{}>\n", h))
+ .collect();
+
+ builder = builder.header_contents("coreaudio.h", &meta_header.concat());
+
+ // Generate the bindings.
+ builder = builder.trust_clang_mangling(false).derive_default(true);
+
+ let bindings = builder.generate().expect("unable to generate bindings");
+
+ // Write them to the crate root.
+ bindings
+ .write_to_file(out_dir.join("coreaudio.rs"))
+ .expect("could not write bindings");
+}
+
+fn main() {
+ let target = std::env::var("TARGET").unwrap();
+ if !(target.contains("apple-darwin") || target.contains("apple-ios")) {
+ panic!("coreaudio-sys requires macos or ios target");
+ }
+
+ let directory = sdk_path(&target).ok();
+ build(directory.as_ref().map(String::as_ref), &target);
+}
diff --git a/third_party/rust/coreaudio-sys/src/lib.rs b/third_party/rust/coreaudio-sys/src/lib.rs
new file mode 100644
index 0000000000..c85c8e8eaf
--- /dev/null
+++ b/third_party/rust/coreaudio-sys/src/lib.rs
@@ -0,0 +1,6 @@
+#![cfg(any(target_os = "macos", target_os = "ios"))]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+#![allow(non_upper_case_globals)]
+
+include!(concat!(env!("OUT_DIR"), "/coreaudio.rs"));