nning / protonutils

CLI tool providing utilities for Proton: List games by version, Download/update GE/Luxtorpeda, clean unused runtimes, clean unused compatdata, ...
MIT License
36 stars 0 forks source link

Can't build from AUR #8

Closed L1Q closed 2 years ago

L1Q commented 2 years ago
[l1q@l1q-mj protonutils-build]$ git clone https://aur.archlinux.org/protonutils.git
Cloning into 'protonutils'...
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 58 (delta 26), reused 58 (delta 26), pack-reused 0
Receiving objects: 100% (58/58), 17.63 KiB | 17.63 MiB/s, done.
Resolving deltas: 100% (26/26), done.
[l1q@l1q-mj protonutils-build]$ cd ./protonutils/
[l1q@l1q-mj protonutils]$ makepkg
==> Making package: protonutils 1.2.7-1 (Mon 29 Nov 2021 06:30:14 PM EET)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Downloading protonutils-1.2.7.tar.gz...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   125  100   125    0     0   1089      0 --:--:-- --:--:-- --:--:--  1096
100 33427    0 33427    0     0  68063      0 --:--:-- --:--:-- --:--:--  895k
==> Validating source files with sha256sums...
    protonutils-1.2.7.tar.gz ... Passed
==> Extracting sources...
  -> Extracting protonutils-1.2.7.tar.gz with bsdtar
==> Starting prepare()...
==> Starting build()...
rm -f cmd/protonutils/protonutils
cd cmd/protonutils; go build -ldflags "-X main.Version=v1.2.7 -X main.Buildtime=20211129163014 -s -w -linkmode external -extldflags \"-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now\"" -trimpath -buildmode=pie -mod=readonly -modcacherw
build flag -mod=readonly only valid when using modules
make: *** [Makefile:20: cmd/protonutils/protonutils] Error 1
==> ERROR: A failure occurred in build().
    Aborting...
[l1q@l1q-mj protonutils]$ go version
go version go1.17.3 linux/amd64
[l1q@l1q-mj protonutils]$
nning commented 2 years ago

Thanks for reporting this issue!

As far as I can tell, it's connected to your LDFLAGS configuration. Passing LDFLAGS from the environment to the Go linker seems to be an Arch Go package guideline requirement: https://aur.archlinux.org/packages/protonutils/#comment-835684

However, as far as I can tell, this only applies to dependencies using C code and protonutils currently does not use any.

Feel free to retest with different LDFLAGS; I will need some time to setup a VM again and figure this out.

L1Q commented 2 years ago

What should be in my LDFLAGS? It's currently empty.

nning commented 2 years ago

I also tested with empty LDFLAGS as I recall. I did not yet have the chance to retest in a VM, though.

nning commented 2 years ago

I also tested with Go 1.17.3 and with the same go build ... command (should mean, we used the same CLFAGS and LDFLAGS).

Excerpt from my makepkg.conf:

CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions \
        -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \
        -fstack-clash-protection -fcf-protection"
CXXFLAGS="$CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"

But I think the idea that LDFLAGS could be the problem is wrong anyway... :smile:

-mod=readonly is recommended in the Arch Linux Go package guidelines but it seems it's unneccessary since Go 1.16 anyway.

I removed the option from the Makefile, released v1.2.9 and updated the PKGBUILD. Please let me know if it works for you!

Thanks for reporting & testing!

L1Q commented 2 years ago
==> Making package: protonutils 1.2.9-1 (Sat 04 Dec 2021 10:00:23 PM EET)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Found protonutils-1.2.9.tar.gz
==> Validating source files with sha256sums...
    protonutils-1.2.9.tar.gz ... Passed
==> Removing existing $srcdir/ directory...
==> Extracting sources...
  -> Extracting protonutils-1.2.9.tar.gz with bsdtar
==> Starting prepare()...
==> Sources are ready.
==> Making package: protonutils 1.2.9-1 (Sat 04 Dec 2021 10:00:26 PM EET)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> WARNING: Using existing $srcdir/ tree
==> Starting build()...
rm -f cmd/protonutils/protonutils
cd cmd/protonutils; go build -ldflags "-X main.Version=v1.2.9 -X main.Buildtime=20211204200026 -s -w -linkmode external -extldflags \"-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now\"" -trimpath -buildmode=pie -modcacherw
build flag -modcacherw only valid when using modules
make: *** [Makefile:20: cmd/protonutils/protonutils] Error 1
==> ERROR: A failure occurred in build().
    Aborting...
nning commented 2 years ago

-modcacherw was also suggested by the Arch guidelines and it's not useful for protonutils. I removed it and released v1.2.10. For me, the build works on Fedora and in a Arch Linux container (with recent archlinux:base-devel image).

L1Q commented 2 years ago

it still failed on my end and here is how

cd cmd/protonutils; go build -ldflags "-X main.Version=v -X main.Buildtime=20211205122116 -s -w -linkmode external -extldflags \"\"" -trimpath -buildmode=pie
ge.go:18:2: cannot find package "github.com/dustin/go-humanize" in any of:
        /usr/lib/go/src/github.com/dustin/go-humanize (from $GOROOT)
        /home/l1q/Documents/tmp/protonutils-build/aur/protonutils/src/gopath/src/github.com/dustin/go-humanize (from $GOPATH)
appid.go:7:2: cannot find package "github.com/nning/protonutils/steam" in any of:
        /usr/lib/go/src/github.com/nning/protonutils/steam (from $GOROOT)
        /home/l1q/Documents/tmp/protonutils-build/aur/protonutils/src/gopath/src/github.com/nning/protonutils/steam (from $GOPATH)
ge.go:20:2: cannot find package "github.com/nning/protonutils/utils" in any of:
        /usr/lib/go/src/github.com/nning/protonutils/utils (from $GOROOT)
        /home/l1q/Documents/tmp/protonutils-build/aur/protonutils/src/gopath/src/github.com/nning/protonutils/utils (from $GOPATH)
appid.go:8:2: cannot find package "github.com/spf13/cobra" in any of:
        /usr/lib/go/src/github.com/spf13/cobra (from $GOROOT)
        /home/l1q/Documents/tmp/protonutils-build/aur/protonutils/src/gopath/src/github.com/spf13/cobra (from $GOPATH)
main.go:8:2: cannot find package "github.com/spf13/cobra/doc" in any of:
        /usr/lib/go/src/github.com/spf13/cobra/doc (from $GOROOT)
        /home/l1q/Documents/tmp/protonutils-build/aur/protonutils/src/gopath/src/github.com/spf13/cobra/doc (from $GOPATH)
make: *** [Makefile:20: cmd/protonutils/protonutils] Error 1

This got me thinking: if it can't find modules now and all the errors I was getting were all about "when using modules" it has to do with the go config. Now that you tested it on your container and have it working I'm even more sure. I did export GO111MODULE=on before running makepkg and got it built with no problem.

[l1q@l1q-mj protonutils]$ export GO111MODULE=on
[l1q@l1q-mj protonutils]$ makepkg
==> Making package: protonutils 1.2.10-1 (Sun 05 Dec 2021 02:25:12 PM EET)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Found protonutils-1.2.10.tar.gz
==> Validating source files with sha256sums...
    protonutils-1.2.10.tar.gz ... Passed
==> Extracting sources...
  -> Extracting protonutils-1.2.10.tar.gz with bsdtar
==> Starting prepare()...
src dir is /home/l1q/Documents/tmp/protonutils-build/aur/protonutils/src
==> Removing existing $pkgdir/ directory...
==> Starting build()...
rm -f cmd/protonutils/protonutils
cd cmd/protonutils; go build -ldflags "-X main.Version=v1.2.10 -X main.Buildtime=20211205122512 -s -w -linkmode external -extldflags \"-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now\"" -trimpath -buildmode=pie
go: downloading github.com/spf13/cobra v1.2.1
go: downloading github.com/MrWaggel/gosteamconv v0.0.0-20190214041723-97e1fbb6de26
go: downloading github.com/andygrunwald/vdf v1.0.0
go: downloading github.com/dustin/go-humanize v1.0.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.1
go: downloading github.com/russross/blackfriday/v2 v2.1.0
==> Entering fakeroot environment...
==> Starting package()...
==> Tidying install...
  -> Removing libtool files...
  -> Purging unwanted files...
  -> Removing static library files...
  -> Stripping unneeded symbols from binaries and libraries...
  -> Compressing man and info pages...
==> Checking for packaging issues...
==> Creating package "protonutils"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Leaving fakeroot environment.
==> Finished making: protonutils 1.2.10-1 (Sun 05 Dec 2021 02:25:23 PM EET)
[l1q@l1q-mj protonutils]$

Tested 1.2.8 PKGBUILD with export GO111MODULE=on right before export CGO_CPPFLAGS="$CPPFLAGS" and it built perfectly fine too. So the -mod=readonly and -modcacherw can be safely restored.

L1Q commented 2 years ago

so yeah, restore the flags, here is how build() should look like in PKGBUILD:

build() {
  cd $pkgname-$pkgver

  export GO111MODULE=on
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export CGO_LDFLAGS="$LDFLAGS"

  make clean build_pie VERSION=v$pkgver

  ./cmd/$pkgname/$pkgname -m man1

  go clean -modcache
}
L1Q commented 2 years ago

see this issue for example https://github.com/golangci/golangci-lint/issues/1502#issuecomment-752095870

nning commented 2 years ago

Nice discovery, thanks for your help! I updated the PKGBUILD and also restored the two build options (although I'm not sure, they are of much use).