Automate asio sys build (#804)

This commit is contained in:
Ali Somay 2023-10-17 12:13:30 +02:00 • committed by GitHub
parent f51589c552
commit 3a449538b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 182 additions and 42 deletions

View file

@ -51,44 +51,46 @@ WASAPI including access to large numbers of channels and lower-latency audio
processing.
CPAL allows for using the ASIO SDK as the audio host on Windows instead of
WASAPI. To do so, follow these steps:
WASAPI.
1. **Download the ASIO SDK** `.zip` from [this
link](https://www.steinberg.net/en/company/developers.html). The version as
of writing this is 2.3.1.
2. Extract the files and place the directory somewhere you are happy for it to stay
(e.g. `~/.asio`).
3. Assign the full path of the directory (that contains the `readme`, `changes`,
`ASIO SDK 2.3` pdf, etc) to the `CPAL_ASIO_DIR` environment variable. This is
necessary for the `asio-sys` build script to build and bind to the SDK.
4. `bindgen`, the library used to generate bindings to the C++ SDK, requires
### Locating the ASIO SDK
The location of ASIO SDK is exposed to CPAL by setting the `CPAL_ASIO_DIR` environment variable.
The build script will try to find the ASIO SDK by following these steps in order:
1. Check if `CPAL_ASIO_DIR` is set and if so use the path to point to the SDK.
2. Check if the ASIO SDK is already installed in the temporary directory, if so use that and set the path of `CPAL_ASIO_DIR` to the output of `std::env::temp_dir().join("asio_sdk")`.
3. If the ASIO SDK is not already installed, download it from <https://www.steinberg.net/asiosdk> and install it in the temporary directory. The path of `CPAL_ASIO_DIR` will be set to the output of `std::env::temp_dir().join("asio_sdk")`.
In an ideal situation you don't need to worry about this step.
### Preparing the build environment
1. `bindgen`, the library used to generate bindings to the C++ SDK, requires
clang. **Download and install LLVM** from
[here](http://releases.llvm.org/download.html) under the "Pre-Built Binaries"
section. The version as of writing this is 7.0.0.
5. Add the LLVM `bin` directory to a `LIBCLANG_PATH` environment variable. If
section. The version as of writing this is 17.0.1.
2. Add the LLVM `bin` directory to a `LIBCLANG_PATH` environment variable. If
you installed LLVM to the default directory, this should work in the command
prompt:
```
setx LIBCLANG_PATH "C:\Program Files\LLVM\bin"
```
6. If you don't have any ASIO devices or drivers available, you can [**download
3. If you don't have any ASIO devices or drivers available, you can [**download
and install ASIO4ALL**](http://www.asio4all.org/). Be sure to enable the
"offline" feature during installation despite what the installer says about
it being useless.
7. **Loading VCVARS**. `rust-bindgen` uses the C++ tool-chain when generating
bindings to the ASIO SDK. As a result, it is necessary to load some
environment variables in the command prompt that we used to build our project.
On 64-bit machines run:
4. Our build script assumes that Microsoft Visual Studio is installed. The script will try to find `vcvarsall.bat`
and execute it with the right machine architecture regardless of the Microsoft Visual Studio version.
If there are any errors encountered in this process which is unlikely,
you may find the `vcvarsall.bat` manually and execute it with your machine architecture as an argument.
The script will detect this and skip the step.
A manually executed command example for 64 bit machines:
```
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
```
On 32-bit machines run:
```
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
```
Note that, depending on your version of Visual Studio, this script might be
in a slightly different location.
8. Select the ASIO host at the start of our program with the following code:
5. Select the ASIO host at the start of our program with the following code:
```rust
let host;
@ -100,7 +102,7 @@ WASAPI. To do so, follow these steps:
If you run into compilations errors produced by `asio-sys` or `bindgen`, make
sure that `CPAL_ASIO_DIR` is set correctly and try `cargo clean`.
9. Make sure to enable the `asio` feature when building CPAL:
6. Make sure to enable the `asio` feature when building CPAL:
```
cargo build --features "asio"
@ -112,8 +114,5 @@ WASAPI. To do so, follow these steps:
```toml
cpal = { version = "*", features = ["asio"] }
```
In the future we would like to work on automating this process to make it
easier, but we are not familiar enough with the ASIO license to do so yet.
*Updated as of ASIO version 2.3.3.*