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

Nix and COREAUDIO_SDK_PATH fails to find AudioUnit/AudioUnit.h #78

Open
simlay opened this issue Apr 2, 2023 · 8 comments
Open

Nix and COREAUDIO_SDK_PATH fails to find AudioUnit/AudioUnit.h #78

simlay opened this issue Apr 2, 2023 · 8 comments

Comments

@simlay
Copy link
Member

simlay commented Apr 2, 2023

Hmm, even with this, i still get this error:

error: failed to run custom build command for `coreaudio-sys v0.2.12`

Caused by:
  process didn't exit successfully: `/Users/foo/foo/target/debug/build/coreaudio-sys-56627feab3b3008a/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=COREAUDIO_SDK_PATH
  cargo:rustc-link-lib=framework=AudioUnit
  cargo:rustc-link-lib=framework=CoreAudio
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS

  --- stderr
  /Users/foo/.cargo/registry/src/github.com-1ecc6299db9ec823/coreaudio-sys-0.2.12/coreaudio.h:1:10: fatal error: 'AudioUnit/AudioUnit.h' file not found
  thread 'main' panicked at 'unable to generate bindings: ClangDiagnostic("/Users/foo/.cargo/registry/src/github.com-1ecc6299db9ec823/coreaudio-sys-0.2.12/coreaudio.h:1:10: fatal error: 'AudioUnit/AudioUnit.h' file not found\n")', /Users/foo/.cargo/registry/src/github.com-1ecc6299db9ec823/coreaudio-sys-0.2.12/build.rs:150:39
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I experienced it on Monterey, upgraded to Ventura (13.3) out of curiosity and still see it. I'm not sure what the latest is settings i should use are, but i have the env set to:

foo@foo ~/foo (main) [101]> echo $COREAUDIO_SDK_PATH
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
foo@foo ~/foo (main)> xcrun --sdk macosx --show-sdk-path
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

Though i'm also using Nix (on Mac, ofc), and trying various things to get it working there with no luck either. Perhaps this should be a new issue.

Any thoughts? Note that coreaudio-sys is currently on 0.2.12. I also tried it against master to no avail.

edit: Hmm, no this looks to be a completely unrelated error? Just lots of path finding errors in this repo, all unique .. hm. Apologies, will open a new issue.

Originally posted by @leeola in #75 (comment)

@simlay
Copy link
Member Author

simlay commented Apr 2, 2023

I'm honestly not sure what's causing this error.

Like, I'm betting you have a /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioUnit.h? which is the header it's trying to include. I believe that Bindgen/llvm knows to look in the System/Library/Frameworks/<framework>.framework/Headers/Header.h but I don't know how to configure that for a non-default setup. The part of cargo:rustc-link-lib=framework=AudioUnit is for rustc link against it.

@leeola
Copy link

leeola commented Apr 2, 2023

Yup,

foo@foo ~/foo (main)> ll /Library/Developer/CommandLineTools/SDKs/
total 0
lrwxr-xr-x 1 root wheel  14 Apr  2 13:39 MacOSX.sdk -> MacOSX13.3.sdk
drwxr-xr-x 7 root wheel 224 Apr  2 13:39 MacOSX12.3.sdk
lrwxr-xr-x 1 root wheel  14 Apr  2 13:38 MacOSX12.sdk -> MacOSX12.3.sdk
drwxr-xr-x 7 root wheel 224 Nov 12 13:18 MacOSX13.1.sdk
drwxr-xr-x 7 root wheel 224 Mar  9 16:58 MacOSX13.3.sdk
lrwxr-xr-x 1 root wheel  14 Apr  2 13:37 MacOSX13.sdk -> MacOSX13.3.sdk
foo@foo ~/foo (main)> ll /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/
total 64K
-rw-r--r-- 1 root wheel   38 Mar  4 09:50 AUAudioUnit.h
-rw-r--r-- 1 root wheel   52 Mar  4 09:50 AUAudioUnitImplementation.h
-rw-r--r-- 1 root wheel   40 Mar  4 09:50 AUCocoaUIView.h
-rw-r--r-- 1 root wheel   38 Mar  4 09:50 AUComponent.h
-rw-r--r-- 1 root wheel 3.2K Mar  4 09:50 AUComponent.r
-rw-r--r-- 1 root wheel   39 Mar  4 09:50 AUParameters.h
-rw-r--r-- 1 root wheel   37 Mar  4 09:50 AudioCodec.h
-rw-r--r-- 1 root wheel   41 Mar  4 09:50 AudioComponent.h
-rw-r--r-- 1 root wheel   42 Mar  4 09:50 AudioOutputUnit.h
-rw-r--r-- 1 root wheel  662 Mar  4 09:50 AudioUnit.h
-rw-r--r-- 1 root wheel  453 Mar  4 09:50 AudioUnit.r
-rw-r--r-- 1 root wheel   46 Mar  4 09:50 AudioUnitCarbonView.h
-rw-r--r-- 1 root wheel  538 Mar  4 09:50 AudioUnitCarbonView.r
-rw-r--r-- 1 root wheel   46 Mar  4 09:50 AudioUnitParameters.h
-rw-r--r-- 1 root wheel   46 Mar  4 09:50 AudioUnitProperties.h
-rw-r--r-- 1 root wheel   38 Mar  4 09:50 MusicDevice.h

Trying to determine where it's actually looking right now. Assuming it isn't looking in that location.. at least.

@PlumpMath
Copy link

Currently, the fyrox engine is using 'coreaudio-sys,' and the build is failing in the same way on x86-64 darwin (Nix-Darwin). However, it builds successfully and runs without issues on m2.

ipetkov/crane#329 (reply in thread)

FyroxEngine/Fyrox#53

@reckenrode
Copy link

reckenrode commented May 23, 2023

When building with Nix, you have to use rustPlatform.bindgenHook in your derivation to make sure builds can find the required frameworks. The installed SDKs don’t matter because Nix doesn’t use them (normally). If you’re using a devShell, try adding it to the shell’s packages.

@TheButlah
Copy link

TheButlah commented Aug 28, 2023

I tried to figure this out for a few hours, with no luck. Here was the flake.nix I unsuccessfully used.
Does anyone know how to solve it? Like @leeola, the header is present on my system, I just assume that nix sandboxes against it.

{
  description = "skilltree flake";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    # eachDefaultSystem and other utility functions
    utils.url = "github:numtide/flake-utils";
    # Replacement for rustup
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, utils, fenix, }:
    # This helper function abstracts over the host platform.
    # See https://github.com/numtide/flake-utils#eachdefaultsystem--system---attrs
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        # Brings in the rust toolchain from the standard file
        # that rustup/cargo uses.
        rustToolchain = fenix.packages.${system}.fromToolchainFile {
          file = ./rust-toolchain.toml;
          sha256 = "sha256-Q9UgzzvxLi4x9aWUJTn+/5EXekC98ODRU1TwhUs9RnY=";
        };
        rustPlatform = pkgs.makeRustPlatform.override { stdenv = pkgs.clangStdenv; }  {
          inherit (rustToolchain) cargo rustc;
        };
        llvm = pkgs.llvmPackages;
        # See https://discourse.nixos.org/t/develop-shell-environment-setup-for-macos/11399/6
        coreAudio = if pkgs.stdenv.isDarwin then
          pkgs.symlinkJoin {
            name = "sdk";
            paths = with pkgs.darwin.apple_sdk.frameworks; [
              AudioToolbox
              AudioUnit
              CoreAudio
              CoreFoundation
              CoreMIDI
              OpenAL
            ];
            postBuild = ''
              mkdir $out/System
              mv $out/Library $out/System
            '';
          }
        else
          "";
      in
      # See https://nixos.wiki/wiki/Flakes#Output_schema
      {
        # `nix develop` pulls all of this in to become your shell.
        devShells.default = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
          nativeBuildInputs = [
            rustToolchain
            rustPlatform.bindgenHook

            # Common cargo tools we often use
            pkgs.cargo-deny
            pkgs.cargo-expand
            pkgs.cargo-binutils
          ];
          buildInputs = [
            # This is missing on mac m1 nix, for some reason.
            # see https://stackoverflow.com/a/69732679
            pkgs.libiconv
            coreAudio
          ];
          # NOTE: coreaudio-sys still doesn't build despite my best efforts! If
          # you know how to fix this please reach out.
          shellHook = ''
            export LIBCLANG_PATH="${llvm.libclang.lib}/lib"
            export COREAUDIO_SDK_PATH="${coreAudio}"
          '';
        };
        # This only formats the nix files.
        formatter = pkgs.nixpkgs-fmt;
      }
    );
}

@reckenrode
Copy link

reckenrode commented Aug 28, 2023

This works for me. The only modifications I made were to pass the dependencies directly and drop the shell hook. rustPlatform.bindgenHook takes care of setting up your environment, so you don’t need to do it manually.

I had to create a rust-toolchain.toml (I used a 1.71 toolchain) and an empty project with coreaudio-sys as a dependency, but cargo build successfully built the project along with the coreaudio-sys crate.

@TheButlah
Copy link

Weird, that does solve it.
For what its worth, I also got it working this way:
https://github.com/NexusSocial/skilltree/blob/28884ebc75a2be6f781a7c08db0e049df6ff30ce/flake.nix
I replaced the frameworks with just Cocoa, after referencing fishfolk's jumpy in nixpkgs.

I think I like @reckenrode's approach more though.

@leeola
Copy link

leeola commented Apr 21, 2024

This works for me. The only modifications I made were to pass the dependencies directly and drop the shell hook. rustPlatform.bindgenHook takes care of setting up your environment, so you don’t need to do it manually.

I had to create a rust-toolchain.toml (I used a 1.71 toolchain) and an empty project with coreaudio-sys as a dependency, but cargo build successfully built the project along with the coreaudio-sys crate.

This worked for me as well. Thank you!

eugenehp added a commit to eugenehp/coreaudio-sys that referenced this issue Jun 6, 2024
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

No branches or pull requests

5 participants