Skip to content

sourcepkg: add a complete source package build #8

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

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/sourcepkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Source Package

on:
push:
branches:
- main

pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: "go.mod"

- name: Run build & test
run: |
cd sourcepkg
make check
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
libtailscale.so
libtailscale.a
libtailscale.h
libtailscale.tar*
/ruby/tmp/
/ruby/pkg/
/ruby/doc/
/ruby/ext/libtailscale/*.go
/ruby/ext/libtailscale/go.mod
/ruby/ext/libtailscale/go.sum
/ruby/LICENSE
/ruby/LICENSE
/sourcepkg/libtailscale
/sourcepkg/libtailscale.tar*
/vendor/
31 changes: 31 additions & 0 deletions sourcepkg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) Tailscale Inc & AUTHORS
# SPDX-License-Identifier: BSD-3-Clause

# Construct a source package by vendoring all source and packing it up into a
# tarball.

ifeq ($(shell uname -s),Darwin)
TAR?=gtar
else
TAR?=tar
endif

all: check

check: libtailscale.tar.zst
@echo "Checking that the tarball is self-contained..."
test `$(TAR) tf libtailscale.tar.zst | grep -c -v '^libtailscale/'` -eq 0 || (echo "Tarball is not self-contained!" && exit 1)

@tar xf libtailscale.tar.zst
@echo "Checking that the tarball is usable..."
@cd libtailscale && ./configure && make


clean:
rm -rf ./libtailscale.tar.zst ../vendor ./libtailscale

../vendor: ../go.mod ../go.sum ../tailscale.go Makefile.src Makefile
go mod vendor

libtailscale.tar.zst: Makefile.src configure ../vendor ../LICENSE ../tailscale.go ../go.mod ../go.sum
$(TAR) --transform 's#^#libtailscale/#' --transform 's#Makefile.src#Makefile#' -acf $@ Makefile.src configure ../vendor ../LICENSE ../tailscale.go ../go.mod ../go.sum
43 changes: 43 additions & 0 deletions sourcepkg/Makefile.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) Tailscale Inc & AUTHORS
# SPDX-License-Identifier: BSD-3-Clause

prefix?=/usr/local
libdir?=$(prefix)/lib
includedir?=$(prefix)/include

all: libtailscale.a libtailscale.so libtailscale.pc

libtailscale.a:
go build -trimpath -buildvcs=false -buildmode=c-archive -o libtailscale.a

libtailscale.so:
go build -trimpath -buildvcs=false -buildmode=c-shared -o libtailscale.so

# TODO(raggi): the dylib build currently fails to build for amd64 on macOS on an
# M1, the toolchain reports a build constraints error despite no build
# constraints.
libtailscale.dylib:
GOARCH=amd64 GOOS=darwin go build -trimpath -buildmode=c-shared -o libtailscale.dylib.amd64 .
GOARCH=arm64 GOOS=darwin go build -trimpath -buildmode=c-shared -o libtailscale.dylib.arm64 .
lipo -create -output libtailscale.dylib libtailscale.dylib.amd64 libtailscale.dylib.arm64

libtailscale.pc:
echo "prefix=/usr/local" > libtailscale.pc
echo "exec_prefix=\$${prefix}" >> libtailscale.pc
echo "libdir=\$${exec_prefix}/lib" >> libtailscale.pc
echo "includedir=\$${prefix}/include" >> libtailscale.pc
echo "" >> libtailscale.pc
echo "Name: libtailscale" >> libtailscale.pc
echo "Description: Tailscale library" >> libtailscale.pc
echo "Version: 0.0.1" >> libtailscale.pc
echo "Libs: -L\$${libdir} -ltailscale" >> libtailscale.pc
echo "Cflags: -I\$${includedir}" >> libtailscale.pc

install: libtailscale.a libtailscale.so libtailscale.pc
install -d $(DESTDIR)$(libdir)
install -m 644 libtailscale.a $(DESTDIR)$(libdir)
install -m 644 libtailscale.so $(DESTDIR)$(libdir)
install -d $(DESTDIR)$(libdir)/pkgconfig
install -m 644 libtailscale.pc $(DESTDIR)$(libdir)/pkgconfig
install -d $(DESTDIR)$(includedir)
install -m 644 *.h $(DESTDIR)$(includedir)
5 changes: 5 additions & 0 deletions sourcepkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libtailscale - Source package

This directory contains extra code included in the `libtailscale` source
package. The source package can be built using the `Makefile` in the top level
project directory.
5 changes: 5 additions & 0 deletions sourcepkg/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
# Copyright (c) Tailscale Inc & AUTHORS
# SPDX-License-Identifier: BSD-3-Clause

go version > /dev/null 2>&1 || { echo >&2 "A Go compiler is required."; exit 1; }