Open simlay opened 1 year ago
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.
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.
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.
https://github.com/ipetkov/crane/discussions/329#discussioncomment-5974313
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
.
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;
}
);
}
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.
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.
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, butcargo build
successfully built the project along with the coreaudio-sys crate.
This worked for me as well. Thank you!
Hmm, even with this, i still get this error:
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:
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 againstmaster
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 https://github.com/RustAudio/coreaudio-sys/issues/75#issuecomment-1493439673