pololu / nixcrpkgs

Tools for cross-compiling standalone applications using Nix.
Other
200 stars 17 forks source link

MacOS build fails on NixOS #8

Closed Bob620 closed 2 years ago

Bob620 commented 2 years ago

This is my first experience with nixcrpkgs.

I initially cloned and ran the repo on my nixos machine for windows and it worked perfectly (for windows).

Unfortunately, I need to also support mac and here is where the issues started.

The first issue is that the macos/gen_sdk_package.sh does not work(?) with current XCode. It silently fails after finding Xcode. I remedied this by cloning tpoechtrager/osxcross and using their up-to-date tools/gen_sdk_package.sh.

After transferring the MacOSX sdk file over to my nix machine and running macos.hello to compile the hello example app. After a bit it gave me the error ls: cannot access 'usr/include/c++/iterator': No such file or directory.

The issue seems to be the same as #4 where the SDKSettings.json and usr/include/c++/v1/iterator may not be the best options to check for anymore. The commit #4 provides, 28dc022, does not seem to work either as XCode uses BPlist rather than just Plist.

As commented in #4

However, since everything still worked without the check as best I can tell, it seems reasonable to just drop it entirely.

I tried just removing the ls check and it all compiled properly and created a working Mac build, however It had no UI. No clue how to even go about debugging that issue as it doesn't throw any errors.

When running the program on the same Mac that the SDK was made on:

Last login: Fri May  6 16:50:23 on ttys002
markie@Markie ~ % /Volumes/public/hello ; exit;
Hello, World!
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

And when run manually via terminal:

markie@Markie ~ % /Volumes/public/hello
Hello, World!
markie@Markie ~ %

Mac was only used to generate the sdk and run the final compiled program, otherwise everything was run on the nix box.

DavidEGrayson commented 2 years ago

The hello world program is just supposed to print "hello world", so it seems like you were able to get it compiled and working successfully.

I will have to spend some time later understanding why the ls check failed and gen_sdk_package.sh failed and what to do about it. It is unfortunate that the macOS SDK cannot be downloaded directly from Apple or redistributed, so that is why you have to go through some extra steps.

DavidEGrayson commented 2 years ago

Everything should be fixed now. I updated nixcrpkgs to use the latest gen_sdk_package.sh script from the osxcross project and I updated my sdk_builder.sh script to fix the redundant v1 directory. I tested that macos.hello_cpp compiles successfully both using my old MacOS10.14.sdk.tar.xz and a MacOS12.3.sdk.tar.bz2 which I just generated today.