Skip to content
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

Statically linked executable #547

Closed
alandefreitas opened this issue Mar 20, 2024 · 2 comments · Fixed by #559 or #603
Closed

Statically linked executable #547

alandefreitas opened this issue Mar 20, 2024 · 2 comments · Fixed by #559 or #603
Assignees
Labels
Bug Something isn't working Feature Something new that it should do

Comments

@alandefreitas
Copy link
Collaborator

alandefreitas commented Mar 20, 2024

Because of how time-consuming it is to build mrdocs, the way mrdocs is supposed to be used is with scripts that download portable executables and run the tool. These scripts will usually be run in CI on some ubuntu-X container. So we need to provide portable executables people can use.

The problem is we're using recent versions of ubuntu (ubuntu 23.04 now) because of the C++ features we need but users (including the boost release scripts) are usually using earlier versions of ubuntu (usually from 18.04 to 22.04) for a variety of reasons. And binaries built on ubuntu X (say 23.04) don't work under ubuntu <X (say 20.04).

I read about the solutions people proposed in #boost and wrote this summary of alternatives to the problem. I'm initially tempted to experiment with musl and a system libs wrapper.

Most solutions above would require us to rebuild all dependencies with -static/musl/cosmopolitan/-ffreestanding and might end up depending on other tools. Each solution is also quite complex and with lots of caveats. There's no way to know if it's going to work before testing.

  1. Some people reported -static/-static-libgcc worked sometimes
    • It's also the first thing I tried but I couldn't get it to work (more details in the PR)
      • Compiling with -static gives us an error when trying to link nlibtinfo.so
      • -static-libgcc still asks for GLIBC_2.36 in ubuntu 20.04 when looking for libc.so.6
    • Another example is https://www.github.com/muttleyxd/clang-tools-static-binaries
      • It uses -static-libgcc and builds LLVM with -DDBUILD_SHARED_LIBS=OFF -DLLVM_BUILD_STATIC=ON
      • I'm not sure -static-libgcc really works there or if it just works because they're compiling the tools with ubuntu-20.04 which should have no conflicts with later versions of ubuntu anyway
  2. Use musl
  3. Use cosmopolitan
    • Also a libc worth trying
    • I haven't found examples using C++ yet
  4. A wrapper overriding system libs
  5. GCC -ffreestanding compile mode
  6. A combination of Mrdocs downgrading ubuntu and release-tools upgrading ubuntu
    • Would it be even possible to use ubuntu-22.04 in the release-tools docker container?
  7. ApBuild: a gcc wrapper that enforces GLIB_C version and does few other binary compatibility tricks
@alandefreitas
Copy link
Collaborator Author

alandefreitas commented Apr 2, 2024

Update:

  1. -static-libgcc won't work for us because libc is part of the kernel.
  2. ❌musl won't work with the C++ version we need. The latest C++/musl toolchain is GCC 11.
  3. ❌Cosmopolitan is very experimental and attempts to be much more general than what we need
  4. A wrapper is still an option
  5. ffreestanding won't work for us because we need access to all C++ features
  6. ❌Mrdocs downgrading ubuntu is still an option but it's very hard to achieve (I tried to achieve this for weeks in ci: create release for Ubuntu 20.04 #562)
  7. ❌ApBuild is not being maintained

So we're left with 4) the wrapper and 6) adjusting Ubuntu versions.

I'll first experiment with the possibility of installing a recent version of Clang and libc++ on Ubuntu 20.04 and building MrDocs this way. MrDocs would use libc++. If that works, we can use that as the official Linux release, which will work on Ubuntu >20.04. This should solve the problem with Boost release-tools.

@alandefreitas
Copy link
Collaborator Author

As described in #562 (comment), solution 6 (Mrdocs downgrading ubuntu) didn't work very well: it's overly complex, hard to maintain, slow to test, not general enough, and it just failed to work properly.

Considering these limitations, the next idea I'll explore to solve #547 is solution (4) a wrapper overriding system libs. This strategy is somewhat similar to what APBuild does but it's manual and more stable. It's similar to how CMake provides its binaries. It basically consists of patching the release so that:

  • The libraries required by MrDocs are identified and bundled with the MrDocs release in subdirectories of lib
  • bin/mrdocs is renamed mrdocs.real (or something to this end)
  • A C wrapper is compiled to replace the original bin/mrdocs
    • This wrapper adjusts the library paths and calls mrdocs.real is compiled with a very old version of GCC and Ubuntu
    • The wrapper can be compiled once or in CI

This has the following benefits:

  • This wrapper also seemed like a complex solution at first but it turns out to be much simpler and more effective than the other solutions we tried.
  • It's easy to maintain. We can use the same logic and the same wrapper no matter what version of Ubuntu we originally used to compile MrDocs. This also means we have more freedom to upgrade the MrDocs toolchain and use more recent C++ standards.
  • Testing is much easier because there's no specific workflow for these binaries. This is a patched version of the same binaries we've been producing. Also, it involves no custom-built compilers.
  • It's a much more general solution. We can build MrDocs on Ubuntu 23.04 and use the release binaries on Ubuntu 16.04 if we have to.

@alandefreitas alandefreitas self-assigned this May 14, 2024
@alandefreitas alandefreitas moved this to In progress in MrDocs May 14, 2024
@alandefreitas alandefreitas moved this from In progress to Backlog in MrDocs May 14, 2024
@alandefreitas alandefreitas moved this from Backlog to In progress in MrDocs May 14, 2024
@alandefreitas alandefreitas added Feature Something new that it should do Bug Something isn't working labels May 15, 2024
alandefreitas added a commit to alandefreitas/mrdocs that referenced this issue May 29, 2024
@alandefreitas alandefreitas linked a pull request May 29, 2024 that will close this issue
alandefreitas added a commit that referenced this issue May 29, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in MrDocs May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Feature Something new that it should do
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant