walles / moar

Moar is a pager. It's designed to just do the right thing without any configuration.
Other
585 stars 17 forks source link

building from source - no version #201

Closed daniejstriata closed 3 months ago

daniejstriata commented 3 months ago

I'm building moar using build.sh from the Source tar.gz. When I build it I don't get the version returned at all. It is just an empty line: image

can the script only be used when in the git repo?

MaximumWoahverdrive commented 3 months ago

The script uses git describe so yes it will only properly set the version if git is installed and the folder is a git repo. "Source code" archives from releases/tags and similar will result in an empty version string being set since version information cannot be determined. You can just edit the script to eg. hard-code a version but that may not be desired.

walles commented 3 months ago

What's your use case for wanting --version to work after building from source archives?

I want to get this working for you, but to do that I need to know what you're trying to achieve.

daniejstriata commented 3 months ago

@walles I'm building a RPM and wanted to use the provided shell scripts in the RPM's SPEC but instead went with:

GO111MODULE=on CGO_ENABLED=0 go build -v -trimpath -modcacherw -tags netgo -ldflags="-s -w -X main.versionString=%{version}" -o "%{name}"

Once I have the package I can install it with a cron that checks for installed package and version to check if it needs an update.

MaximumWoahverdrive commented 3 months ago

How do actually get the source files then? I'm not familiar with RPM SPEC but the simplest way I see would be something along the lines of:

git clone https://github.com/walles/moar
cd moar
git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
./build.sh

Ofcourse, you could

daniejstriata commented 3 months ago

If you build in Fedora COPR. Each build runs in a temporary environment that gets deleted once the build completes.

When you build something, ideally the source would be supplied at build time, usually in form of a tar.gz. This could get patched by rpmbuild before compiling the source.

To build something, to be added in Fedora, all dependencies would need to be packaged as well. Copr is much more relaxed, you could do exactly what you explained above, but if you build using too open sources it could be a problem if the supply chain is compromised. I'm building these for my own use but if anyone wants to use them they'd be free to as my copr repo is not private. (It's also just for Amazon Linux 2023) https://copr.fedorainfracloud.org/coprs/faramirza/al2023/ COPR can build RPMs for most distros using rpm packages.

walles commented 3 months ago

I guess this means you managed to package it?

https://copr.fedorainfracloud.org/coprs/faramirza/al2023/package/moar/

daniejstriata commented 3 months ago

It's packaged. Are you happy with the build command I used?

GO111MODULE=on CGO_ENABLED=0 go build -v -trimpath -modcacherw -tags netgo '-ldflags=-s -w -X main.versionString=1.23.7' -o moar
walles commented 3 months ago

It's packaged. Are you happy with the build command I used?

GO111MODULE=on CGO_ENABLED=0 go build -v -trimpath -modcacherw -tags netgo '-ldflags=-s -w -X main.versionString=1.23.7' -o moar

Here's what I'd go with:

go build -v -trimpath '-ldflags=-s -w -X main.versionString=1.23.7' -o moar

GO11MODULE is not needed. Unsure whether it hurts.

I don't think CGO_ENABLED=0 has any effect, so I'd drop it.

-trimpath: Nice find, I'm stealing it for the official builds!

-modcacherw: I tried to read up on it, and I'm unsure, but if you can build without it that at least simplifies your build script.

-tags netgo: Most often the default anyway, unsure of the value of forcing it, docs say they "prefer the go resolver by default" anyway