-
-
Notifications
You must be signed in to change notification settings - Fork 337
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
Support compiling Miniaudio under Cosmopolitan #495
Comments
That is an interesting project. Have you tried compiling miniaudio with it as-is? If so, what errors did you encounter? miniaudio uses pre-processor macros for platform detection such as |
I did, and I only remember getting a lot of errors. I'll go set up my Cosmo environment and dump them all here if you want. I don't know about Cosmo platform macros. The Cosmo Github repository has a lot of examples. One of them displays a small GUI on Windows only and has the following code snippet:
I imagine that macros like WIN32 would either be not defined or even if they were, they wouldn't be reliable since it can run on multiple platforms. Looks like platform detection is about as easy as it could be, assuming there are functions such as IsLinux and IsMacOs. |
I'd be curious to see the errors if possible. If there's a huge amount, maybe attach it as a text file. This seems like an interesting project, but I'm a bit undecided at the moment. miniaudio depends very heavily on those platform detection macros for it's build system and I'm not sure the work involved to work around all that is worth it. I'll sit on this for a bit and think about it. |
If you want a way to know when Miniaudio is compiling under Cosmopolitan, there's probably a 'cosmo' macro or something you can check at compile time. I'd be surprised if there wasn't one. I'm compiling the Cosmopolitan static library which is really large because it's full of Windows API stubs that are each in their own .O file so the linker, I believe, can remove dead code. A hello world binary is only about 40KB though, so it must be working. I'll get you the errors when it's done |
I've spent a few hours looking at this. I got it compiling at a very basic level, but there's a lot to consider here. The first thing is the whole "cosmopolitan.h" thing. It looks to me that they want you to use that monolithic header for everything which does not work well for miniaudio because we need to use the standard include system for other compilers. To work around this, you'll need to use something like https://github.com/fabriziobertocci/cosmo-include and point the compiler to it with I pushed a fix for some general cross-platform compatibility issues, but this does not make it work cleanly across all platforms and all backends. For one, Cosmo does not support a lot of Win32 stuff from what I can tell, including common things like As it stands in the dev branch right now, I believe only the PulseAudio, JACK and null backends work. The ALSA backend depends on The BSD platforms all depend on some platform-specific audio headers which I don't believe are supported by Cosmo so they would need some work to get working as well. Android, iOS/macOS and Web will never be supported due to too many dependencies on platform-specific code. |
I've played around with this a bit more and unfortunately it looks like it's not going to work. I got it compiling with all three Windows backends (WASAPI, DirectSound and WinMM), but it doesn't run. miniaudio makes extensive use of I think the Cosmopolitan project needs time to mature before taking it too seriously in miniaudio. There's a lot missing from their Windows headers as a start. They also need to make it work better as a drop-in replacement for GCC before it'll be truly useful. If they add support for The code as it stands at the time of writing will compile, but I won't be putting any active effort into maintaining it. |
Thanks for the work. Instead of using cosmopolitan.h, there are libc-like headers in https://github.com/jart/cosmopolitan/tree/master/libc/isystem. |
Yes they've got I wasn't aware of that isystem thing, but good to know. Thanks. I scratch my head as to why that's not the default option... |
Cosmopolitan author here. I'm looking into what needs to change on our end to get miniaudio working well with cosmocc (see https://justine.lol/cosmo3/) because https://github.com/Mozilla-Ocho/llamafile/ has need of this. One of the things I noticed for example is that you want |
It's been a long while since I experimented with Cosmo so I can't remember the exact details, but miniaudio uses dynamic linking at runtime via Also, I think from memory the windows headers were very incomplete, but I suspect that at the time the pre-packaged SDK might have been out of date and therefore I was using an old version. Not sure how that's changed since. I'm happy to reopen this and revisit Cosmo when I get a chance. |
Cosmopolitan is a C standard library that allows building statically linked binaries that run under Windows, Mac, Linux and a few other platforms all at the same time. Since it does not have an easy / good way to play audio (AKA Miniaudio) and Miniaudio is already cross-platform, it seems like it'd be a pretty good fit, however it might be a good bit of work. Since these binaries could run anywhere, it'd have to contain code for all supported backends, then at runtime we detect the platform and enable the right ones.
I believe Cosmopolitan wraps a lot of the Windows API and allows calling into it pretty easily but you'll get an error code at runtime if not on Windows. Don't know about anything else, but we link to those at runtime which might make things easier. Hopefully these links help:
Building actually portable executables on Windows
Cosmopolitan home page
Cosmopolitan on Github
The text was updated successfully, but these errors were encountered: