summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 199775890fdecc06d9e3912d1a847f7beb24d4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Maintainer: Timothy Gu <timothygu99@gmail.com>
# Contributor: Morten Linderud <foxboron@archlinux.org>
# Contributor: David Anderson <dave@natulte.net>

pkgname=tailscale-git
_pkgname=tailscale
pkgver=1.59.6+t4e822c031
pkgrel=1
pkgdesc="A mesh VPN that makes it easy to connect your devices, wherever they are."
arch=("x86_64")
url="https://tailscale.com"
license=("MIT")
makedepends=("git")
depends=("glibc")
optdepends=('networkmanager: DNS resolver integration'
            'openresolv: DNS resolver integration'
            'systemd: DNS resolver integration with systemd-resolved')
provides=($_pkgname)
conflicts=($_pkgname)
backup=("etc/default/tailscaled")
source=("git+https://github.com/tailscale/$_pkgname.git")
sha256sums=('SKIP')
install="tailscale.install"

pkgver() {
  cd "${_pkgname}"
  eval "$(./build_dist.sh shellvars)"
  echo "$VERSION_LONG" | sed 's/-/+/g'
}

prepare() {
    cd "${_pkgname}"
    TOOLCHAIN="$PWD/../tailscale-go" tool/go mod vendor
    # go mod vendor can contribute some changes to go.mod or go.sum.
    # Revert them so that the version stamp in "tailscale version" doesn't have
    # "-dirty" suffix.
    git restore go.mod go.sum
}

build() {
    cd "${_pkgname}"

    # https://wiki.archlinux.org/title/Go_package_guidelines#Flags_and_build_options
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

    # The version stamp flags mirror build_dist.sh. However, we have to
    # duplicate that logic since we also want to set -linkmode=external, and Go
    # has no way of merging ldflags specified through GOFLAGS with those in the
    # command line: https://github.com/golang/go/issues/26849
    eval "$(./build_dist.sh shellvars)"
    GO_LDFLAGS="\
        -linkmode=external \
        -X tailscale.com/version.longStamp=${VERSION_LONG} \
        -X tailscale.com/version.shortStamp=${VERSION_SHORT}"

    for cmd in ./cmd/tailscale ./cmd/tailscaled; do
        TOOLCHAIN="$PWD/../tailscale-go" ./build_dist.sh -ldflags "$GO_LDFLAGS" $cmd
    done
}

#TODO: Figure out why tests are failing
# check() {
#     cd "${_pkgname}"
#     go test $(go list ./... | grep -v tsdns_test)
# }

package() {
    cd "${_pkgname}"
    install -Dm755 tailscale tailscaled -t "$pkgdir/usr/bin"
    install -Dm644 cmd/tailscaled/tailscaled.defaults "$pkgdir/etc/default/tailscaled"
    install -Dm644 cmd/tailscaled/tailscaled.service -t "$pkgdir/usr/lib/systemd/system"
    install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}