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

Fix nix flake for macOS #2595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niklaskorz
Copy link

@niklaskorz niklaskorz commented Sep 13, 2023

  1. Generate outputs for all systems through flake-utils (x86_64 and aarch64 linux and darwin)
  2. Add Carbon framework as build input on darwin, required by
    #include <Carbon/Carbon.h>
  3. Make some build inputs Linux specific: X11, mesa, alsa, jack2, pulseaudio
  4. Move git to native build inputs (only relevant for cross compiling; native build inputs are specific to the host system, build inputs for the target system)
  5. Only generate the static library libgpac_static.a if STATIC_MODULES is set. Nix prefers dynamic libraries (and actually passes a --disable-static to configure by default) and the static library adds unnecessary bloat. Furthermore, the presence of the static library seems to break the final binary (both gpac and MP4Box) in the Nix flake output for reasons I don't know yet (crashes immediately with [1] 4966 killed result/bin/gpac), but with the static library disabled, everything is fine.
  6. Remove the custom build phases as the default ones defined by Nix do the same (as long as enableParallelBuilding = true is defined).

@niklaskorz
Copy link
Author

🦗

@aureliendavid
Copy link
Member

Hi,

Sorry for the delayed response.

@RodolpheFouquet : would you mind having a look at the nix flake part if you have some time?

Regarding point 5, it is intended behavior to have the static lib built alongside the dynamic one when doing a standard build. I am reticent to change this for a niche use case (it seems to be ok on nix flake for linux and for non-flake builds). Maybe you can add a workaround to remove/ignore it for this particular case?

@RodolpheFouquet
Copy link
Member

First @niklaskorz, thank you very much for your contribution.

Hi, I will have a look later this week. I do not have access to the Mac right now.

Only generate the static library libgpac_static.a if STATIC_MODULES is set. Nix prefers dynamic libraries (and actually passes a --disable-static to configure by default) and the static library adds unnecessary bloat. Furthermore, the presence of the static library seems to break the final binary (both gpac and MP4Box) in the Nix flake output for reasons I don't know yet (crashes immediately with [1] 4966 killed result/bin/gpac), but with the static library disabled, everything is fine.

Agreed, the default should remain building both libraries as many internal GPAC script (and gpac test infrastructure) relies on this behaviour. I think DISABLE_STATIC shoud be the option, and be set by the flake to only.

We could still use a nix build argument to reenable static if needed.

@niklaskorz
Copy link
Author

niklaskorz commented Dec 5, 2023

Can you clarify what these variables in configure are for:

gpac/configure

Lines 92 to 94 in 666daf2

static_build="no"
static_bin="no"
static_modules="no"

If static builds should be enabled by default but with the option to disable them, shouldn't one of these variables (or all of them?) be set to "yes" by default? I'm fine adding another generic static = "yes" variable (which would then be set to "no" by --disable-static) if none of the existing variables is meant to control static library compilation.

@rbouqueau
Copy link
Member

@niklaskorz I guess --static-build should be sufficient.

@aureliendavid
Copy link
Member

Can you clarify what these variables in configure are for:

gpac/configure

Lines 92 to 94 in 666daf2

static_build="no"
static_bin="no"
static_modules="no"

these variables control the following switches described in the configure help:

  --static-build           link statically against libgpac but still allow dependencies to shared libraries (enable --static-modules)
  --static-bin             enable static linking of MP4Box and gpac only (will enable --static-build), disable all libraries not linkable statically.
  --static-modules         embed modules in libgpac rather than using dynamic library modules

so they all control a different thing than whether or not the static libgpac is built at all, that's why they are all set to no by default.

I guess adding a --disable-static to completely disable building libgpac_static.a could make sense. (but it would also be easier to let it build as is and just ignore/remove the lib you don't want a posteriori)

@rbouqueau
Copy link
Member

What's the status here?

@RodolpheFouquet RodolpheFouquet changed the base branch from master to feature/improve-nix-flake April 28, 2024 01:27
@RodolpheFouquet RodolpheFouquet changed the base branch from feature/improve-nix-flake to master April 28, 2024 01:28
@RodolpheFouquet
Copy link
Member

Hi, I am sorry for the delay, I have reviewed the PR and it works, however:

  • I think --disable-static should be handle properly, a new config param should be introduced in our config.mak to handle it. I do not want to steal your work, so you can use the branch I have just created https://github.com/gpac/gpac/tree/feature/improve-nix-flake to modify your branch
  • we should mark static builds as unsupported on nix with Darwin. Nix uses glibtool and not the Apple libtool and supporting it requires more work (we can open an issue for that).

I have tested the PR on NixOS unstable and on MacOS sonoma with Apple silicon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants