cpal icon indicating copy to clipboard operation
cpal copied to clipboard

ai::* not found on build with feature asio

Open nck974 opened this issue 2 years ago • 7 comments

I'm using the following code:

pub fn initialize_host() -> cpal::host {
    let host;
    #[cfg(target_os = "windows")]
    {
        host = cpal::host_from_id(cpal::HostId::Asio).expect("failed to initialise ASIO host");
    }
    host
}

With this dependecy:

[dependencies]
cpal = { version = "0.15.2", features = ["asio"] }

I added the sdk to the path:

$env:CPAL_ASIO_DIR 
C:\Users\<my_path>\driver\windows\asiosdk_2.3.3_2019-06-14
Directory: C:\Users\<my_path>\driver\windows\asiosdk_2.3.3_2019-06-14


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
da----         8/19/2023   8:38 AM                asio
da----         8/19/2023   8:38 AM                common
da----         8/19/2023   8:38 AM                driver
da----         8/19/2023   8:38 AM                host
-a----         8/19/2023   8:38 AM        1022497 ASIO SDK 2.3.pdf
-a----         8/19/2023   8:38 AM            787 changes.txt
-a----         8/19/2023   8:38 AM           1976 readme.txt
-a----         8/19/2023   8:38 AM         146295 Steinberg ASIO 2.3.3 Licensing Agreement 2.0.1 - 2019.pdf
-a----         8/19/2023   8:38 AM        4158326 Steinberg ASIO Logo Artwork.zip

I installed clang:

https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.0/LLVM-16.0.0-win64.exe
$env:LIBCLANG_PATH 
C:\Program Files\LLVM\bin

When I build the project I get the following compilation errors:

cargo build
   Compiling winapi v0.3.9
   Compiling memchr v2.5.0
   Compiling proc-macro2 v1.0.66
   Compiling unicode-ident v1.0.11
   Compiling libc v0.2.147
   Compiling glob v0.3.1
   Compiling autocfg v1.1.0
   Compiling version_check v0.9.4
   Compiling regex-syntax v0.7.4
   Compiling nom v5.1.3
   Compiling unicode-width v0.1.10
   Compiling clang-sys v1.6.1
   Compiling textwrap v0.11.0
   Compiling vec_map v0.8.2
   Compiling bitflags v1.3.2
   Compiling quote v1.0.33
   Compiling aho-corasick v1.0.4
   Compiling windows_x86_64_msvc v0.48.5
   Compiling humantime v2.1.0
   Compiling strsim v0.8.0
   Compiling log v0.4.20
   Compiling bindgen v0.56.0
   Compiling which v3.1.1
   Compiling rustc-hash v1.1.0
   Compiling peeking_take_while v0.1.2
   Compiling lazy_static v1.4.0
   Compiling lazycell v1.3.0
   Compiling windows_x86_64_msvc v0.42.2
   Compiling regex-automata v0.3.6
   Compiling shlex v0.1.1
   Compiling syn v1.0.109
   Compiling winapi-util v0.1.5
   Compiling atty v0.2.14
   Compiling libloading v0.7.4
   Compiling termcolor v1.2.0
   Compiling same-file v1.0.6
   Compiling clap v2.34.0
   Compiling cexpr v0.4.0
   Compiling walkdir v2.3.3
   Compiling num-traits v0.2.16
   Compiling lock_api v0.4.10
   Compiling cc v1.0.82
   Compiling parking_lot_core v0.9.8
   Compiling regex v1.9.3
   Compiling windows-targets v0.48.5
   Compiling smallvec v1.11.0
   Compiling env_logger v0.8.4
   Compiling scopeguard v1.2.0
   Compiling cfg-if v1.0.0
   Compiling windows-targets v0.42.2
   Compiling cpal v0.15.2
   Compiling once_cell v1.18.0
   Compiling windows v0.46.0
   Compiling parking_lot v0.12.1
   Compiling dasp_sample v0.11.0
   Compiling num-derive v0.3.3
   Compiling asio-sys v0.2.1
error[E0531]: cannot find unit struct, unit variant or constant `kAsioSelectorSupported` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:877:13
    |
877 |         ai::kAsioSelectorSupported => {
    |             ^^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioResetRequest` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:880:23
    |
880 |                 | ai::kAsioResetRequest
    |                       ^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioEngineVersion` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:881:23
    |
881 |                 | ai::kAsioEngineVersion
    |                       ^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioResyncRequest` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:882:23
    |
882 |                 | ai::kAsioResyncRequest
    |                       ^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioLatenciesChanged` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:883:23
    |
883 |                 | ai::kAsioLatenciesChanged
    |                       ^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioSupportsTimeInfo` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:885:23
    |
885 |                 | ai::kAsioSupportsTimeInfo
    |                       ^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioSupportsTimeCode` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:886:23
    |
886 |                 | ai::kAsioSupportsTimeCode
    |                       ^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioSupportsInputMonitor` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:887:23
    |
887 |                 | ai::kAsioSupportsInputMonitor => 1,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioResetRequest` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:892:13
    |
892 |         ai::kAsioResetRequest => {
    |             ^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioResyncRequest` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:901:13
    |
901 |         ai::kAsioResyncRequest => {
    |             ^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioLatenciesChanged` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:911:13
    |
911 |         ai::kAsioLatenciesChanged => {
    |             ^^^^^^^^^^^^^^^^^^^^^ not found in `ai`
error[E0531]: cannot find unit struct, unit variant or constant `kAsioEngineVersion` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:919:13
    |
919 |         ai::kAsioEngineVersion => {

   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:925:13
    |
925 |         ai::kAsioSupportsTimeInfo => {
    |             ^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

error[E0531]: cannot find unit struct, unit variant or constant `kAsioSupportsTimeCode` in module `ai`
   --> C:\Users\<my_user>\.cargo\registry\src\github.com-1ecc6299db9ec823\asio-sys-0.2.1\src\bindings\mod.rs:932:13
    |
932 |         ai::kAsioSupportsTimeCode => {
    |             ^^^^^^^^^^^^^^^^^^^^^ not found in `ai`

For more information about this error, try `rustc --explain E0531`.
error: could not compile `asio-sys` due to 14 previous errors

I think i have followed carefully all instructions and I don't know what else can I check from here. I cleaned multiple times the build.

Environment:

Windows 10
cargo 1.69.0 (6e9a83356 2023-04-12)

nck974 avatar Aug 19 '23 07:08 nck974

Any hint on how can I debug this? I can not even compile the basic example. The environment variables configured, and the sdk can not be downloaded in older versions.,.

nck974 avatar Aug 23 '23 20:08 nck974

I finally was able to found out what is going on. It seems the current crate published in crate.io does not correspond with the code that is in the git repository with version 0.15.2. Therefore when you just use the dependency it will not include 718d49ef5ee3714482051c188fe274533fa2b2b9 and therefore not build.

I was able to build using the git repository as dependency as a temporary patch: cpal = { git = "https://github.com/RustAudio/cpal.git", features = ["asio"] }

nck974 avatar Aug 24 '23 06:08 nck974

I finally was able to found out what is going on. It seems the current crate published in crate.io does not correspond with the code that is in the git repository with version 0.15.2. Therefore when you just use the dependency it will not include 718d49e and therefore not build.

I was able to build using the git repository as dependency as a temporary patch: cpal = { git = "https://github.com/RustAudio/cpal.git", features = ["asio"] }

Ran into the same problem, thanks for the workaround :)

the-drunk-coder avatar Aug 30 '23 10:08 the-drunk-coder

I finally was able to found out what is going on. It seems the current crate published in crate.io does not correspond with the code that is in the git repository with version 0.15.2. Therefore when you just use the dependency it will not include 718d49e and therefore not build.

I was able to build using the git repository as dependency as a temporary patch: cpal = { git = "https://github.com/RustAudio/cpal.git", features = ["asio"] }

For those who ran into the same problem, but also has dependencies that also depends on cpal (like rodio), use this instead:

[patch.crates-io]
cpal = { git = "https://github.com/RustAudio/cpal.git", branch = "master", commit = "f51589c" }

profetia avatar Sep 23 '23 04:09 profetia

I was having a similar issue, it is great that there is a work around and it worked for me also. Is there any plan to fix this in the stable release soon? It would have been nice because it is not possible to publish a crate with git dependencies.

alisomay avatar Oct 12 '23 23:10 alisomay

thank you all so much for finding a workaround. Would this be fixed by publishing a new release?

thomvil avatar Jan 14 '24 10:01 thomvil