ExPixel / miniaudio-rs

Rust bindings for miniaudio C library.
https://crates.io/crates/miniaudio
MIT License
49 stars 20 forks source link

Update target checks to support cross-compilation #73

Open kofigumbs opened 3 years ago

kofigumbs commented 3 years ago

Currently miniaudio-sys/build.rs uses the cfg! macro to determine the platform flags, but it seems like those values are not accurate for build.rs scripts. I think it's' implied by this part of the Cargo docs:

Cargo sets several environment variables when build scripts are run. Because these variables are not yet set when the build script is compiled, the above example using env! won't work and instead you'll need to retrieve the values when the build script is run:

This PR swaps the cfg! macro for the environment variables mentioned in the book. In my project, I encountered this when trying to cross-compile for wasm32 from macOS. Before the change, setting --target would have no effect on the miniaudio flags: I would still see cargo:rustc-cfg=feature="ma-enable-coreaudio" in the build log for instance. Now, when I target wasm32/emscripten, I see that the -webaudio is enabled and -coreaudio is not.

I see that you have a CI GitHub workflow, but please let me know if there's any other testing you'd like to see. I lifted the implementation from https://github.com/paritytech/rust-snappy/blob/1195dfa43e1e9b69464d5105d65ceea2619331c7/snappy-sys/build.rs#L26-L28

Fixes #39.