space-wizards / RobustToolbox

Robust multiplayer game engine, used by Space Station 14
https://spacestation14.io
Other
536 stars 395 forks source link

Refactor native library compilation stack #4997

Open PJB3005 opened 5 months ago

PJB3005 commented 5 months ago

The system we have for compiling native libraries for Robust is currently a mess. We need to clean this up so we can distribute natives to all platforms consistently (Fluidsynth/OpenAL Soft on macOS), distribute new libraries (SDL2) and be able to do updates to these more easily. This is currently blocking ARM support (#1443).

Background

Native libraries right now are shoddily cobbled together from a few sources. Some libraries we get from third-party NuGet packages[^1]. The rest we distribute ourselves (via our own NuGet packages we publish to nuget.org), and they are put together with a combination of "compiled ourselves" and "downloaded from the project's website"[^2].

In the latter case, https://github.com/space-wizards/build-dependencies is responsible for both containing a record of these dlls and containing the NuGet packaging files used to produce the native libraries.

When we compile natives ourselves, the scripts for doing so are stored in https://github.com/space-wizards/native-build, but they're a complete unstandardized mess.

The problem

The native libraries we get from third-party NuGets are mostly fine (well, I haven't had any issues yet).

The native libraries we publish via NuGet are a pain in the ass. It's a ton of manual work that requires doing stuff on at least three operating systems. Bonus points we keep losing the PDB files so debugging is impossible.

I would like to see the following improvements made:

[^1]: e.g. libsodium: https://www.nuget.org/packages/libsodium [^2]: e.g. GLFW: https://github.com/space-wizards/build-dependencies/tree/343d4dee05495241c3e49bebc54ee6cc4383daf9/natives/glfw/3.3

rene-descartes2021 commented 5 months ago

Using vcpkg instead for these is a very good idea.

In a company environment I found the idea of distributing and also consuming 3rd party (compiled) native libraries via NuGet to be unacceptable. So much that when I authored such NuGet packages I improvised a way for NuGet to obtain and build such libraries from source (via nmake and MSBuild magic), with plumbing for proper include and link flags. Then vcpkg came about a couple years later- I'm happy they made that.

rene-descartes2021 commented 4 months ago

I will tackle this. Here is proposed design:

I'll put vcpkg as a submodule at /Tools/vcpkg/. I'll design its use such that no extra manual steps beyond existing dotnet build are required, i.e. no ./vcpkg/bootstrap.sh, vcpkg integrate, or vcpkg install zstd sdl1 libsodium etc, via:

vcpkg has ports for angle, libsodium, glfw, freetype, fluidsynth, openal-soft, zstd, sdl1, and sdl2. vcpkg can be configured to look elsewhere for ports (via vcpkg-configuration.json), for the ones space-wizards forked. Looks like there is a port for angle with patches that space-wizards uses. vcpkg does not have ports for CEF, or space-wizards/nativefiledialog.

Any problems with this design let me know. Downsides may be additional storage space(?) and additional time MSBuild uses for each compile, will try to mitigate if issue.

moonheart08 commented 4 months ago

I don't think we ever plan to ship src instead of natives. Do not PR anything that builds libraries from source please, the entire point of the prebuilt natives is they're prebuilt.

We need a src compilation step yes but it is not to be part of the main repos, we publish the built natives to nuget for ease of building for all downstreams and game programmers.

PJB3005 commented 4 months ago

Yes absolutely, natives need to stay prebuilt for regular engine development. The thing we're doing in the end (putting them into NuGet packages) is fine. The thing that needs fixing is how those NuGet packages are built.

Having the correct C/C++ compiler and Windows SDK available is a huge extra pile of things that can go wrong, especially for new contributors.

None of this work should change the workflow for regular developers or modify RobustToolbox itself at all, this should all stay in the other repos I linked.

PJB3005 commented 4 months ago

And yes btw for CEF just get the downloads from Spotify's builds CDN. Absolutely not compiling that garbage from scratch even with a new compilation stack.

AverageNotDoingAnythingEnjoyer commented 2 weeks ago

Guess no-one is willing to do it, sigh