6 ms·
Show HN: macOS-cross-compiler – Compile binaries for macOS on Linux
- mmastrac 3y agoGreat to see all of this work brought together like this. I looked into some of these solutions earlier and the licensing status of doing this is pretty grey and likely violates some of the toolchain licenses. For personal use, that's not really an issue. It's far easier than trying to get a decently performing OSX runner somewhere, and I don't see Apple caring at all. Use caution if you are bringing this into a commercial environment.
- o11c 3y agoThe tooling should be mostly fine, it's all the libraries that are the problem. Theoretically this could be avoided by making a stub library, but the way namespacing works on OS X means that's tricky.
- rfoo 3y ago> it's all the libraries that are the problem And also header files which are also part of macOS SDK, as the project claims to support C codes.
- cmiller1 3y agoWhat is happening with that first picture?? Is that an extra penguin arm coming out of the apple?
- fao_ 3y agoThe penguin is holding the apple, unfortunately rather than commissioning an actual artist they've seemingly gone for AI art, so the penguin also has three arms. The left foot with the third arm there is also a bit... weird and deformed.
- mistercow 3y agoIt’s a project with 20 GitHub stars which wraps up existing tooling to make a fairly niche need easier. The expectation that they’d commission an artist to produce a fun hero image for the readme seems a little odd.
- Turing_Machine 3y agoThese are volunteers providing hundreds (at a guess) of hours of unpaid labor to a project they're giving away for free. You also expect them to pay an artist out of their own pockets? Maybe an artist (for example, you) could donate his or her time and provide them with a better logo for free.
- devmor 3y agoWhy is this a defense for them using the labor of non-consenting artists to generate a crappy header image? Surely they could ask an artist to volunteer their time just as they volunteered theirs?
- koala_man 3y ago> Surely they could ask an artist to volunteer their time just as they volunteered theirs? Unfortunately "I spent a lot of time on this thing you have no interest in or relation to" is not a very convincing argument in the FOSS world.
- Turing_Machine 3y ago> not a very convincing argument Neither is "I'm not going to contribute a damned thing, but nonetheless the team behind this free product needs to spend more time and/or money to make me happy." If you don't like the logo, well... that sounds a lot like a personal problem to me.
- mistercow 3y agoRandom generated images slapped up in a context where there’s clearly no competing commercial interest just seems like a really silly hill to have this fight on. Even if you take a hard line on the debate on model training data, this is an utterly harmless case, and certainly not worth the gut punch threads like this cause to someone who is just trying to share their open source project with the community. Also, you don’t in fact know that the model used to generate this was trained with art used without consent.
- shepherdjerred 3y agoI actually didn't notice that! I wanted to add some sort of image to the repository README, and it seemed like the simplest way to do so.
- xyst 3y agoI wonder if it will compile natively to arm instructions or rely Rosetta on host machine to perform translation
- brutal_chaos_ 3y ago> A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on an Android smartphone is a cross compiler. https://en.m.wikipedia.org/wiki/Cross_compilation https://en.m.wikipedia.org/wiki/Cross_compilation So compile on Linux, run on macOS without Rosetta
- Alifatisk 3y agoWill this allow me to compile, let's say Crystal scripts to macOS from a Linux machine? Because at the moment, "cross-compilation" with Crystal still requires you to be on the targeted system. https://crystal-lang.org/reference/1.11/syntax_and_semantics/cross-compilation.html https://crystal-lang.org/reference/1.11/syntax_and_semantics...
- deknos 3y agoDoes this not need any xcode/macos license?
- schleck8 3y agoWhy would it? You can cross compile for macos with the go toolchain on Linux too and that doesn't even require an additional compiler. Just GOOS=darwin GOARCH=arm64 and then the regular command. Apple can't regulate everything
- adastra22 3y agoIf you need the macOS SDK, then you need to obey the developer licensing rules. Does this need the SDK?
- duskwuff 3y agoOnly if you're using cgo. If you're building native Go code, the Go compiler is fully self-contained and can target any supported platform from anywhere -- macOS from Linux, Linux from Windows, Android from FreeBSD, you name it.
- breather 3y agoThe most obvious answer is you need the system frameworks to link against.
- sneak 3y agoAre they allowed to redistribute the macOS SDK? I assume that Apple’s EULA doesn’t permit that.
- wyldfire 3y agoSpeaking of cross compilers - I was able to use the zig toolchain in order to cross compile for macos apple silicon, arm Linux, windows x64, windows arm and x86_64 Linux musl (statically linked). It's super handy and works as a drop in.
- vlovich123 3y agoInterestingly you can use zig within your Rust build to more easily cross-compile: https://github.com/rust-cross/cargo-zigbuild https://github.com/rust-cross/cargo-zigbuild I’m curious what the blockers are for rustc to cross-compile like zig does natively.
- adastra22 3y agoJust add another arch with rustup. Am I missing something?
- weinzierl 3y agoThat would solve the compilation problem, but there is more to create a working binary. For MacOS the official (and I believe only legal) way is to use a Mac with XCode installed for linking. Now, you can download all the necessary files from a Mac and build a cross-compilation toolchain on your Linux system. I believe you could not legally distribute a project doing this and that is why these projects don't exist or are usually short-lived (with the notable exception of zig). We will see how that goes for OP. So, solutions like osxcross resort to shipping scripts that help you to acquire the necessary files and make that process easier. The OP builds on osxcross, but is "batteries included". zig has an even more difficult problem to solve because it tries to compile and link for many platforms. Shipping all the different requirements in their original form would make a zig distribution huge. So it does some clever magic I do not fully understand to create the necessary files from just the necessary subset of data. This reduces the size because there is overlap between platforms. It also means that they are not shipping the Mac files in their complete and original form and have gotten away with this legally so far. At least that is what I believe is happening. I hope someone with more knowledge about zig could explain it better.
- my123 3y agoThe problem with this is licensing: the macOS SDK license says that it's only to be used on an "Apple-branded computer". That said I wonder what Apple would do if this is used outside of that case...
- joe_hills 3y agoApple ships extra stickers with their logo in the box with a lot of their products, maybe slap one on your computer and see how far it gets you in court?
- WesolyKubeczek 3y agoWhich is why they changed the wording from "Apple-labeled" to "Apple-branded" around the time of Snow Leopard IIRC.
- thfuran 3y agoHow much could a branding iron cost?
- chihuahua 3y agoThis place [0] sells custom design branding irons starting at $93. 0: https://brandingirons.com/products/basic-fire-heated-branding-package-1-x-1 https://brandingirons.com/products/basic-fire-heated-brandin...
- anon-sre-srm 3y agoIt's cooler to use liquid nitrogen. https://en.wikipedia.org/wiki/Freeze_brand https://en.wikipedia.org/wiki/Freeze_brand
- thfuran 3y agoI don't think that works as well on computers.
- 3y ago
- duped 3y ago> Code signing (but not notarizing) should be possible with this project, but it is untested Code signing is required for aarch64 macs unless they have SIP disabled, so this is kind of important.
- WesolyKubeczek 3y agoThis vastly depends on how you intend to distribute your binaries. I get away with distributing internal tools to my team completely ad-hoc signed, as long as I download them with cURL or SFTP. Downloading with a browser taints them, of course, and gatekeeper will prevent you from running them.
- duped 3y agoTo be clear, it doesn't depend on anything. If SIP is enabled, you cannot run executables on ARM Macs without codesigning (they may be ad hoc signed, sure, but they still need to be signed). The executable will get killed immediately if you don't. You can avoid gatekeeper problems by clearing the xattrs on the file. If they're internal you can also just distribute over a network share and it's not an issue.
- renewiltord 3y agoCurrently I cross-compile the other way since the story is easier. Getting dependencies, etc. especially if you want something libssl is an annoying nightmare if you're trying to cross-compile targeting MacOS on a host on Linux. But if you're going the other way, very easy to use Docker. The good part of this is that I can use a standard Linux host now to just build everything. Very nice!
- jvolkman 3y agoI'll plug some work I've been doing to (attempt to) enable cross compilation of Python wheels. I put together a small example [1] that builds the zstandard wheel, and can build macos wheels on linux and linux wheels on macos using zig cc. macos wheels must still be adhoc signed (codesign) and binary patched (install_name_tool), so I re-implemented those functions in Python [2]. [1] https://github.com/jvolkman/bazel-pycross-zstandard-example https://github.com/jvolkman/bazel-pycross-zstandard-example [2] https://github.com/jvolkman/repairwheel/tree/main/src/repairwheel/macos https://github.com/jvolkman/repairwheel/tree/main/src/repair...
- hamdouni 3y agoI think the project can easily add Go to the list as cross compiling is built-in: GOOS=darwin GOARCH=arm64 go build -o bin/app-silicon-darwin app.go
- wargo 3y agoI've been using goreleaser-cross for cross-compiling Go apps with cgo https://github.com/goreleaser/goreleaser-cross https://github.com/goreleaser/goreleaser-cross
- miduil 3y agoHm, need to give this* a try with NixOS cross compilation for macos. If I could pre-build nix packages for macOS developers on linux build hosts that'd be awesome. *the building blocks
- roblabla 3y agoIf you want to codesign and notarize your binary from linux, you can also use rcodesign[0]! I've been using it in production for about a year, and it's been working great so far. [0]: https://gregoryszorc.com/docs/apple-codesign/stable/ https://gregoryszorc.com/docs/apple-codesign/stable/
- xyzzy_plugh 3y agoThe documentation for this is unbelievably good. Thank you for sharing!
- infogulch 3y agoI feel like a reference to this should be somewhere in the macos-cross-compiler repo.
- dhash 3y agoThis is really cool! I spent the time a couple years back to build a windows sysroot, but having a macOS one was on my mind for a while. Will definitley use
- nektro 3y agogreat to see zig mentioned in the comments
- jhatemyjob 3y agoNo Obj-C????? WHYYYYYY
- shepherdjerred 3y agoGCC has objective C/objective C++ enabled, but I have never tested it.
- mariusbolik 3y agoGreat Project. I have 2 questions: 1. Can this be used to run in a github action? 2. Can this be used to compile ios apps?