Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve asio sys build script #809

Merged
merged 5 commits into from
Nov 11, 2023

Conversation

alisomay
Copy link
Contributor

@alisomay alisomay commented Nov 5, 2023

Improvements

  • vcvarsall.bat is executed exhaustively for any supported host and target architecture combinations now.
  • Downloading the ASIO SDK is working on all platforms now which enables cross compilation.
  • A section on the README.md is added which explains cross compilation scenarios for cpal with the asio feature.
  • vcvarsall.bat search is improved greatly to execute smarter and faster to cover for CI scenarios where the disk I/O might be a bottle neck.
  • A type mismatch bug which was apparent on using the mingw-w64 tool chain is fixed.

With these changes I want to enable:

  • Better building experience in CI
  • Improve existing changes to be cross compilation ready.

What I have tried:

  • macOS aarch64 (host) -> windows x86, x86_64 (target) ✅
  • linux (ubuntu) aarch64 (host) -> windows x86, x86_64 (target) ✅
  • windows aarch64 (host)-> windows x86, x86_64, aarch64 (target) ✅
  • windows x86_64 (host)-> windows x86, x86_64, aarch64 (target) ✅

If I missed something, I'll correct it along the way.
Thank you for the last merge, and I look forward to your review 🙏

@alisomay alisomay force-pushed the improve-asio-sys-build-script branch 3 times, most recently from 3545a50 to ac9b198 Compare November 5, 2023 22:18
@alisomay alisomay force-pushed the improve-asio-sys-build-script branch from ac9b198 to f320944 Compare November 5, 2023 23:03
@alisomay
Copy link
Contributor Author

alisomay commented Nov 5, 2023

I've also checked a bit about the reason why asmjs-wasm32-test fails the CI.
This snippet

#[cfg(target_os = "emscripten")]
impl wasm_bindgen::convert::IntoWasmAbi for BufferSize {
    type Abi = wasm_bindgen::convert::WasmOption<u32>;
    fn into_abi(self) -> Self::Abi {
        match self {
            Self::Default => None,
            Self::Fixed(fc) => Some(fc),
        }
        .into_abi()
    }
}

Has this type wasm_bindgen::convert::WasmOption<u32>.

But that type does not exist anymore in the module.

The changes made to that snippet was 12 months ago and the last time I have checked the CI was green a few weeks ago.

I wonder if my changes made a side effect..

I don't know how it is used in the wild but this may provide a solution:

#[cfg(target_os = "emscripten")]
impl wasm_bindgen::convert::IntoWasmAbi for BufferSize {
    type Abi = u32;
    fn into_abi(self) -> Self::Abi {
        match self {
            Self::Default => 0x00FF_FFFFu32,
            Self::Fixed(fc) => fc,
        }
        .into_abi()
    }
}

I'm trying to mimic https://github.com/rustwasm/wasm-bindgen/blob/962f580d6f5def2df4223588de96feeb30ce7572/src/convert/impls.rs#L114-L140

Where 0x00FF_FFFFu32 is used to bridge None.
It compiles but I don't know if it is the expected behavior.

@alisomay
Copy link
Contributor Author

No significant rush but when approximately you may look at this?
Thanks 🙏

num-traits = "0.2"


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why these blank lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably forgotten, I'll just remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
vec!["C:\\Program Files\\Microsoft Visual Studio\\"]
};
let paths = vec![
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can just be a &[...] right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it can. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn determine_vcvarsall_bat_arch_arg() -> String {
let host_architecture = std::env::consts::ARCH;

let arch_arg = if cfg!(target_arch = "x86_64") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_arch in a build script also refers to the arch of the host, as the build scripts are always compiled for the host.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed confusing. I didn't catch that thanks!

Running this build script on macos aarch64
with the command cargo build --target=x86_64-pc-windows-gnu :

fn main() {
    let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
    let host_architecture = std::env::consts::ARCH;

    if cfg!(target_arch = "x86_64") {
        println!(r#"cfg!(target_arch = "x86_64")"#);
    }

    if cfg!(target_arch = "aarch64") {
        println!(r#"cfg!(target_arch = "aarch64")"#);
    }

    println!(
        "CARGO_CFG_TARGET_ARCH: {}\nstd::env::consts::ARCH: {}",
        target_arch, host_architecture
    );

    panic!();
}

yields

  --- stdout
  cfg!(target_arch = "aarch64")
  CARGO_CFG_TARGET_ARCH: x86_64
  std::env::consts::ARCH: aarch64

which indeed proves the target_arch in the cfg! macro is actually the host arch from my point of view.

I'll apply the changes accordingly replacing those with the target arch parsed from the triple.
I'll also double check if it usesCARGO_CFG_* variables.
rust-lang/cargo#4302

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2d6b063
Fixes it.

@est31
Copy link
Member

est31 commented Nov 10, 2023

I wonder if my changes made a side effect..

I don't think so.

I don't know how it is used in the wild but this may provide a solution:

feel free to make a PR!

@alisomay alisomay requested a review from est31 November 11, 2023 11:27
@est31 est31 merged commit efa0c7a into RustAudio:master Nov 11, 2023
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants