fairyglade / ly

display manager with console UI
Do What The F*ck You Want To Public License
5.33k stars 306 forks source link

How to install to prefix withouth encoding prefix into the binary #629

Closed christian-heusel closed 2 months ago

christian-heusel commented 2 months ago

I want to package ly version 1.0.0 but currently struggle to do so for various reasons (also see #628):

  1. How can I install the binary without modifying/rebuilding it? (old "make install" that just copies everything in place)
  2. How can I set a install prefix that does not get compiled into the binary? Right now it seems like setting -Ddest_directory="$pkgdir" also includes it into the binary:
    $ strings ly-dm | grep /build
    /build/ly/pkg/ly/etc/ly/xsetup.sh
    /build/ly/pkg/ly/etc/ly/wsetup.sh
    /build/ly/pkg/ly/etc/ly/config.ini
    /build/ly/pkg/ly/etc/ly

    This is an issue because it makes ly crash the session on login when the build package is installed onto a real system:

    Jul 02 19:10:26 meterpeter ly-dm[7603]: (==) Log file: "/home/chris/.local/share/xorg/Xorg.0.log", Time: Tue Jul  2 19:10:26 2024
    Jul 02 19:10:26 meterpeter ly-dm[7603]: (==) Using config directory: "/etc/X11/xorg.conf.d"
    Jul 02 19:10:26 meterpeter ly-dm[7603]: (==) Using system config directory "/usr/share/X11/xorg.conf.d"
    Jul 02 19:10:26 meterpeter ly-dm[7617]: zsh:1: no such file or directory: /build/ly/pkg/ly/etc/ly/xsetup.sh
    Jul 02 19:10:27 meterpeter ly-dm[7603]: (II) Server terminated successfully (0). Closing log file.
  3. It would be nice if the value supplied by -Dname=... also did get templated into the systemd unit

For previous versions the install went something like this:

build() {
    make -C "$pkgname"
}

package() {
    cd "$pkgname"

    make DESTDIR="$pkgdir" NAME=ly-dm install installsystemd
    sed -i "s;/usr/bin/ly;/usr/bin/ly-dm;g" "$pkgdir/usr/lib/systemd/system/ly.service"
}

This is where I'm currently at:

build() {
    cd "$pkgname"
    zig build
}

package() {
    cd "$pkgname"

    zig build -Ddest_directory="$pkgdir" -Dname="ly-dm" installsystemd
    # https://github.com/fairyglade/ly/issues/628
    chmod 644 "$pkgdir/etc/pam.d/ly" "$pkgdir/usr/lib/systemd/system/ly.service"
    sed -i "s;/usr/bin/ly;/usr/bin/ly-dm;g" "$pkgdir/usr/lib/systemd/system/ly.service"
}
christian-heusel commented 2 months ago

I can of course move the files into place by hand, but it would IMO be much better (also for packagers in other distros) to properly support this directly in ly.

AnErrupTion commented 2 months ago

Hey there! 👋🏻 Looks like you're running into some unexpected issues, to say the least. 😅

  1. I'm not aware of any way to only run the custom build steps without actually running the build step. That's because the build.zig file is part of the build process, making everything tightly integrated. However, how is that a problem in your case? You could build with the same options as you currently have in build(), and in package() you could simply append installsystemd, and the Zig build system should be smart and not rebuild (since it should be able to tell everything's the same).

  2. That is... unexpected. I checked and what the C version does is just hardcode the /etc/ly path into the binary instead. While I admit I don't like that behavior, we (I and another contributor who worked on this feature) didn't think of this potential (yet common) use case. I think I'll just add a separate build option which would get embedded into the binary instead. How does that sound? Another way I see how this could be fixed is to chroot into a specific file system, but that's either overkill or not very possible from within Arch's build environment.

  3. That's slightly more complicated, given that it's a separate file and would likely require the build system to open the file, replace a special string with the executable name, and write the changes. But it's definitely doable.

christian-heusel commented 2 months ago
  1. [...] You could build with the same options as you currently have in build(), and in package() you could simply append installsystemd

Yeah this works once we solve the problem from 2). I thought this way I could first build the binary and then just move the already built binary 😅

  1. [...] I think I'll just add a separate build option which would get embedded into the binary instead. How does that sound?

A separate build option sounds good! Makefiles use DESTDIR for this (https://www.gnu.org/prep/standards/html_node/DESTDIR.html), maybe we can make the current option into that and add a separate bindir/binary_folder or similar variable for the binary location? 🤔

I don't care much for the specifcs/naming but I thought I might aswell give some input 😆

  1. That's slightly more complicated, given that it's a separate file and would likely require the build system to open the file, replace a special string with the executable name, and write the changes. But it's definitely doable.

Yeah no problem, this is also not changed since the old version so IMO it can stay as is for now 😄

Thanks for the fast response and the helpful comments! 🤗

AnErrupTion commented 2 months ago

@christian-heusel I've pushed the required changes in master and v1.0.x and it seems to work for me. Are you able to test like this or should I push a release anyway?

christian-heusel commented 2 months ago

I can test first and you can publish a release when convenient 😄

christian-heusel commented 2 months ago

Seems to work well, I have published the package to the testing repostories 🤗 https://gitlab.archlinux.org/archlinux/packaging/packages/ly/-/commit/32816171d54912886bc2328b0fe238bc598af823

Thanks for the speedy fix!