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

mindustry: build Arc from source #108274

Merged
1 commit merged into from Jan 11, 2021
Merged

mindustry: build Arc from source #108274

1 commit merged into from Jan 11, 2021

Conversation

ghost
Copy link

@ghost ghost commented Jan 3, 2021

Motivation for this change

Currently we use binary shared libraries from maven. These include statically linked variants of SDL2 and glew from the author's build machine. To run mindustry on wayland without Xwayland it is necessary to link against a different glew library.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ghost
Copy link
Author

ghost commented Jan 8, 2021

This works now, but the whole file definitely needs a cleanup because it is currently very messy.
There are way too many fixed-output derivation hashes that need to be redone on every update. We should automate that with an update script (think nix-universal-prefetch) and also add a check that ensures the hash isn't outdated (like buildRustPackage does with the cargo vendor hash).

@ghost
Copy link
Author

ghost commented Jan 8, 2021

screenshot

@fgaz
Copy link
Member

fgaz commented Jan 8, 2021

I wonder if this fixes the aarch64 build too

@ghost
Copy link
Author

ghost commented Jan 10, 2021

Partially: libsdl-arc64.so can be built, but libarcarm64.so, which is also used for sprite packing at build-time, is still missing. On x86_64-linux this is blob is downloaded from maven. All of these binary downloads that are not easily packagable all the way down are so ugly I can't even, but this is a generic Java problem.
I'm also wondering how this affects non-linux platforms, but it's difficult for me to test this.

@ghost
Copy link
Author

ghost commented Jan 10, 2021

Anuken/Mindustry#1704 (comment)

☹️

full build log for mindustry / mindustry-deps for reference: https://termbin.com/2igz

@ghost
Copy link
Author

ghost commented Jan 10, 2021

I can now build both libarc64.so (via the jnigenBuild task) and libsdl-arc64.so (as before via the sdlnatives task) on x86_64-linux and inject them into the downloaded maven deps before starting the build. This should also make some of the LD_LIBRARY_PATH hacks unnecessary, since libarc64.so now has the correct rpath with alsaLib and so on.
However, porting this to aarch64 will be a bit more difficult: Upstream has some hard-coded compiler flags that can not work with aarch64.

@fgaz
Copy link
Member

fgaz commented Jan 10, 2021

That's unfortunate.

While you're at it then could you set meta.platforms to x86_64 and remove aarch64 from meta.broken, since it's unsupported upstream?

@ghost
Copy link
Author

ghost commented Jan 10, 2021

While you're at it then could you set meta.platforms to x86_64 and remove aarch64 from meta.broken, since it's unsupported upstream?

Done.


Okay, so this has turned into a complete refactor:

  • I didn't like how we had to build the whole project twice each time (once for the -deps), so I investigated a bit and found a solution to only prefetch all dependencies in the -deps derivation, without building anything.
  • By accident I discovered that the Mindustry gradle project will discover an Arc checkout if it's placed in ../Arc (probably mostly intended for development) and use that instead of attempting to download prebuilt versions. So I used this to combine the Arc and Mindustry builds into one derivation, going back to one -deps derivation as well.

This might have broken some more things on darwin, but since it didn't work before and it doesn't look like that problem will be solved soon, I would like to ignore that for now.

@ghost ghost marked this pull request as ready for review January 10, 2021 17:12
Copy link
Member

@fgaz fgaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't like how we had to build the whole project twice each time (once for the -deps), so I investigated a bit and found a solution to only prefetch all dependencies in the -deps derivation, without building anything.

This is great! I also tried to do something like this some time ago but failed miserably...

By accident I discovered that the Mindustry gradle project will discover an Arc checkout if it's placed in ../Arc (probably mostly intended for development) and use that instead of attempting to download prebuilt versions. So I used this to combine the Arc and Mindustry builds into one derivation, going back to one -deps derivation as well.

Also good news! Only two hashes is definitely more manageable. Did you discover a way to find invalid hashes?


Thanks for the PR, +1 from me!

I left some minor comments here and there.

pkgs/games/mindustry/default.nix Outdated Show resolved Hide resolved
pkgs/games/mindustry/default.nix Outdated Show resolved Hide resolved
pkgs/games/mindustry/default.nix Outdated Show resolved Hide resolved
pkgs/games/mindustry/default.nix Outdated Show resolved Hide resolved
pkgs/games/mindustry/default.nix Outdated Show resolved Hide resolved
pkgs/games/mindustry/default.nix Show resolved Hide resolved
@ghost ghost changed the title mindustry: use libs from nixpkgs mindustry: build Arc from source Jan 10, 2021
@ghost ghost requested a review from fgaz January 10, 2021 19:43
@fgaz
Copy link
Member

fgaz commented Jan 11, 2021

Conflict

@ghost
Copy link
Author

ghost commented Jan 11, 2021

Conflict

is resolved

Copy link
Member

@fgaz fgaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. Github still shows it as conflicting. Oh well.

install -Dm644 desktop/build/libs/Mindustry.jar $out/share/mindustry.jar
mkdir -p $out/bin
makeWrapper ${jre}/bin/java $out/bin/mindustry \
${stdenv.lib.optionalString stdenv.isLinux "--prefix LD_LIBRARY_PATH : ${alsaLib}/lib"} \
makeWrapper ${jdk}/bin/java $out/bin/mindustry \
--add-flags "-jar $out/share/mindustry.jar"
install -Dm644 core/assets/icons/icon_64.png $out/share/icons/hicolor/64x64/apps/mindustry.png
install -Dm644 ${desktopItem}/share/applications/Mindustry.desktop $out/share/applications/Mindustry.desktop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait I think you forgot to remove this since you use copyDesktopItems

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, you're right

- reduce the buildPhase of the fixed-output dependencies derivation to
  only download all dependencies, instead of building the full thing.
- add wayland variant, which is linked against a different variant of
  the glew library to run natively using SDL_VIDEODRIVER=wayland
- use jdk (Java 15) instead of jre (Java 8) at runtime
- use new copyDesktopItems hook
@ghost
Copy link
Author

ghost commented Jan 11, 2021

Sorry I forgot to push earlier.

@ghost ghost merged commit e614b5a into NixOS:master Jan 11, 2021
@fgaz
Copy link
Member

fgaz commented Jan 11, 2021

thank you! one binary less in nixpkgs 🎉

@ghost
Copy link
Author

ghost commented Jan 11, 2021

There will probably be a followup PR with some minor refinements and aarch64 support in the next few days (also planning to add aarch64 support upstream)

@chkno chkno mentioned this pull request Oct 28, 2022
13 tasks
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants