Use mask & cross

This commit is contained in:
Dennis Schwerdel 2024-03-19 23:15:04 +01:00
parent 18e4a22210
commit 7e55ec5df6
11 changed files with 211 additions and 354 deletions

View File

@ -1,39 +0,0 @@
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
objcopy = { path = "arm-linux-gnueabihf-objcopy" }
strip = { path = "arm-linux-gnueabihf-strip" }
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
objcopy = { path = "arm-linux-gnueabihf-objcopy" }
strip = { path = "arm-linux-gnueabihf-strip" }
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
objcopy = { path = "arm-linux-gnueabihf-objcopy" }
strip = { path = "arm-linux-gnueabihf-strip" }
[target.arm-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
objcopy = { path = "arm-linux-gnueabihf-objcopy" }
strip = { path = "arm-linux-gnueabihf-strip" }
[target.armv5te-unknown-linux-gnueabi]
linker = "arm-linux-gnueabi-gcc"
objcopy = { path = "arm-linux-gnueabi-objcopy" }
strip = { path = "arm-linux-gnueabi-strip" }
[target.armv5te-unknown-linux-musleabi]
linker = "arm-linux-gnueabi-gcc"
objcopy = { path = "arm-linux-gnueabi-objcopy" }
strip = { path = "arm-linux-gnueabi-strip" }
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
objcopy = { path = "aarch64-linux-gnu-objcopy" }
strip = { path = "aarch64-linux-gnu-strip" }
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
objcopy = { path = "aarch64-linux-gnu-objcopy" }
strip = { path = "aarch64-linux-gnu-strip" }

View File

@ -1,49 +0,0 @@
%define __spec_install_post %{nil}
%define __os_install_post %{_dbpath}/brp-compress
%define debug_package %{nil}
Name: vpncloud
Summary: Peer-to-peer VPN
Version: @@VERSION@@
Release: @@RELEASE@@
License: GPL-3.0
Group: Applications/System
Source0: %{name}-%{version}.tar.gz
URL: https://vpncloud.ddswd.de
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description
%{summary}
%prep
%setup -q
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
mkdir -p %{buildroot}/etc/vpncloud
chmod 700 %{buildroot}/etc/vpncloud
mkdir -p %{buildroot}/lib/systemd/system
mkdir -p %{buildroot}/usr/share/man/man1
cp %{buildroot}/../../../../../assets/example.net.disabled %{buildroot}/etc/vpncloud/example.net.disabled
cp %{buildroot}/../../../../../assets/vpncloud@.service %{buildroot}/lib/systemd/system/vpncloud@.service
cp %{buildroot}/../../../../../assets/vpncloud.target %{buildroot}/lib/systemd/system/vpncloud.target
cp %{buildroot}/../../../../../assets/vpncloud-wsproxy.service %{buildroot}/lib/systemd/system/vpncloud-wsproxy.service
cp %{buildroot}/../../../../../target/vpncloud.1.gz %{buildroot}/usr/share/man/man1/vpncloud.1.gz
cp -a * %{buildroot}
%clean
rm -rf %{buildroot}
%files
/etc/vpncloud
/etc/vpncloud/example.net.disabled
/usr/bin/vpncloud
/lib/systemd/system/vpncloud@.service
/lib/systemd/system/vpncloud.target
/lib/systemd/system/vpncloud-wsproxy.service
/usr/share/man/man1/vpncloud.1.gz
%defattr(-,root,root,-)
%{_bindir}/*

2
Cargo.lock generated
View File

@ -1216,7 +1216,7 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]] [[package]]
name = "vpncloud" name = "vpncloud"
version = "2.3.0" version = "2.4.0"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"chrono", "chrono",

View File

@ -1,19 +1,18 @@
[package] [package]
name = "vpncloud" name = "vpncloud"
version = "2.3.0" version = "2.4.0"
authors = ["Dennis Schwerdel <schwerdel@googlemail.com>"] authors = ["Dennis Schwerdel <schwerdel@googlemail.com>"]
build = "build.rs"
license = "GPL-3.0" license = "GPL-3.0"
description = "Peer-to-peer VPN" description = "Peer-to-peer VPN"
homepage = "https://vpncloud.ddswd.de" homepage = "https://vpncloud.ddswd.de"
repository = "https://github.com/dswd/vpncloud" repository = "https://github.com/dswd/vpncloud"
keywords = ["vpn", "p2p", "tun", "tap", "network"] keywords = ["vpn", "p2p", "tun", "tap", "network"]
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
[package.metadata] [package.metadata]
toolchain = "1.75.0" toolchain = "1.75.0"
upx_version = "3.96" upx_version = "4.2.2"
[dependencies] [dependencies]
chrono = { version = "0.4", features = ["std", "clock"], default_features = false} chrono = { version = "0.4", features = ["std", "clock"], default_features = false}
@ -60,6 +59,7 @@ harness = false
[profile.release] [profile.release]
lto = true lto = true
strip = true
[profile.dev] [profile.dev]
lto = false lto = false
@ -89,8 +89,13 @@ assets = [
["target/vpncloud.1.gz", "/usr/share/man/man1/vpncloud.1.gz", "644"] ["target/vpncloud.1.gz", "/usr/share/man/man1/vpncloud.1.gz", "644"]
] ]
[package.metadata.rpm.cargo] [package.metadata.generate-rpm]
buildflags = ["--release"] assets = [
{ source = "target/release/vpncloud", dest = "/usr/bin/vpncloud", mode = "755" },
[package.metadata.rpm.targets] { source = "assets/example.net.disabled", dest = "/etc/vpncloud/example.net.disabled", mode = "600" },
vpncloud = { path = "/usr/bin/vpncloud" } { source = "assets/vpncloud@.service", dest = "/lib/systemd/system/vpncloud@.service", mode = "644" },
{ source = "assets/vpncloud.target", dest = "/lib/systemd/system/vpncloud.target", mode = "644" },
{ source = "assets/vpncloud-wsproxy.service", dest = "/lib/systemd/system/vpncloud-wsproxy.service", mode = "644" },
{ source = "target/vpncloud.1.gz", dest = "/usr/share/man/man1/vpncloud.1.gz", mode = "644" }
]
auto-req = "no"

View File

@ -1,28 +0,0 @@
// VpnCloud - Peer-to-Peer VPN
// Copyright (C) 2015-2021 Dennis Schwerdel
// This software is licensed under GPL-3 or newer (see LICENSE.md)
use std::{env, fs, path::Path, process::Command};
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
// Process manpage using asciidoctor command
println!("cargo:rerun-if-changed=vpncloud.adoc");
fs::create_dir_all(&out_dir).unwrap();
fs::copy("vpncloud.adoc", Path::new(&out_dir).join("vpncloud.adoc")).unwrap();
match Command::new("asciidoctor")
.args(["-b", "manpage", "vpncloud.adoc"])
.current_dir(Path::new(&out_dir))
.status()
{
Ok(_) => {
Command::new("gzip").args(["vpncloud.1"]).current_dir(Path::new(&out_dir)).status().unwrap();
fs::copy(Path::new(&out_dir).join("vpncloud.1.gz"), "target/vpncloud.1.gz").unwrap();
}
Err(err) => {
println!("cargo:warning=Error building manpage: {}", err);
println!("cargo:warning=The manpage will not be build. Do you have 'asciidoctor'?");
}
}
}

View File

@ -1,2 +0,0 @@
cache
build.sh

View File

@ -1,45 +0,0 @@
FROM ubuntu:16.04
ARG TOOLCHAIN=stable
ARG UPX_VERSION=3.96
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
curl \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \
gcc-arm-linux-gnueabi \
libc6-dev-arm64-cross \
libc6-dev-armhf-cross \
libc6-dev-armel-cross \
libc6-dev-i386 \
gcc-5-multilib \
asciidoctor \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
ENV RUSTUP_HOME=/opt/rust/rustup \
PATH=/opt/rust/cargo/bin:/home/user/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | env CARGO_HOME=/opt/rust/cargo sh -s -- -y --default-toolchain ${TOOLCHAIN} --profile minimal --no-modify-path
RUN env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-gnu \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv5te-unknown-linux-gnueabi \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-gnueabihf \
&& env CARGO_HOME=/opt/rust/cargo rustup target add aarch64-unknown-linux-gnu
RUN env CARGO_HOME=/opt/rust/cargo cargo install cargo-deb \
&& rm -rf /opt/rust/cargo/{git,tmp,registry}
RUN ln -s asm-generic/ /usr/include/asm
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user
RUN mkdir -p /home/user/.cargo \
&& ln -s /opt/rust/cargo/config /home/user/.cargo/config
VOLUME /home/user/.cargo/tmp
VOLUME /home/user/.cargo/git
VOLUME /home/user/.cargo/registry

View File

@ -1,49 +0,0 @@
FROM ubuntu:16.04
ARG TOOLCHAIN=stable
ARG UPX_VERSION=3.96
RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
build-essential \
curl \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \
gcc-arm-linux-gnueabi \
libc6-dev-arm64-cross \
libc6-dev-armhf-cross \
libc6-dev-armel-cross \
libc6-dev-i386 \
gcc-5-multilib \
asciidoctor \
musl musl-dev musl-tools \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
ENV RUSTUP_HOME=/opt/rust/rustup \
PATH=/opt/rust/cargo/bin:/home/user/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | env CARGO_HOME=/opt/rust/cargo sh -s -- -y --default-toolchain ${TOOLCHAIN} --profile minimal --no-modify-path
RUN env CARGO_HOME=/opt/rust/cargo rustup target add x86_64-unknown-linux-musl \
&& env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-musl \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv5te-unknown-linux-musleabi \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-musleabihf \
&& env CARGO_HOME=/opt/rust/cargo rustup target add aarch64-unknown-linux-musl
RUN curl https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz -Lf | tar -xJ --strip-components=1 -C /opt/rust/cargo/bin
RUN ln -s asm-generic/ /usr/include/asm \
&& ln -s /usr/bin/g++ /usr/bin/musl-g++ \
&& ln -s /usr/bin/aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-musl-gcc \
&& ln -s /usr/bin/arm-linux-gnueabihf-gcc /usr/bin/arm-linux-musleabihf-gcc
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user
RUN mkdir -p /home/user/.cargo \
&& ln -s /opt/rust/cargo/config /home/user/.cargo/config
VOLUME /home/user/.cargo/tmp
VOLUME /home/user/.cargo/git
VOLUME /home/user/.cargo/registry

View File

@ -1,34 +0,0 @@
FROM centos:7
ARG TOOLCHAIN=stable
RUN yum groupinstall -y 'Development Tools'
RUN yum install -y ruby && gem install asciidoctor -v 2.0.10
ENV RUSTUP_HOME=/opt/rust/rustup \
PATH=/opt/rust/cargo/bin:/home/user/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | env CARGO_HOME=/opt/rust/cargo sh -s -- -y --default-toolchain ${TOOLCHAIN} --profile minimal --no-modify-path
RUN env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-gnu \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-gnueabihf
RUN env CARGO_HOME=/opt/rust/cargo cargo install cargo-rpm \
&& rm -rf /opt/rust/cargo/{git,tmp,registry}
RUN yum install -y libstdc++-*.i686 \
&& yum install -y glibc-*.i686 \
&& yum install -y libgcc.i686
RUN ln -s /usr/bin/gcc /usr/bin/i686-linux-gnu-gcc
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user
RUN mkdir -p /home/user/.cargo \
&& ln -s /opt/rust/cargo/config /home/user/.cargo/config
VOLUME /home/user/.cargo/tmp
VOLUME /home/user/.cargo/git
VOLUME /home/user/.cargo/registry

View File

@ -1,98 +0,0 @@
#!/bin/bash
function docker_cmd() {
DIST=$1
CMD=$2
mkdir -p $CACHE/$DIST/{target,registry,git,tmp}
docker run -it --rm -v $(pwd)/..:/home/user/code \
-v $CACHE/$DIST/target:/home/user/code/target \
-v $CACHE/$DIST/registry:/home/user/.cargo/registry \
-v $CACHE/$DIST/git:/home/user/.cargo/git \
-v $CACHE/$DIST/tmp:/home/user/.cargo/tmp \
vpncloud-builder-$DIST bash -c "$CMD"
}
# docker run -it --rm -v $(pwd)/..:/home/user/code -v $(pwd)/cache/rpm/target:/home/user/code/target -v $(pwd)/cache/rpm/registry:/home/user/code/registry -v $(pwd)/cache/rpm/git:/home/user/code/git -v $(pwd)/cache/rpm/tmp:/home/user/code/tmp vpncloud-builder-rpm
set -e
cd $(dirname $0)
TOOLCHAIN=$(grep -e '^toolchain =' ../Cargo.toml | sed -e 's/toolchain = "\(.*\)"/\1/')
UPX_VERSION=$(grep -e '^upx_version =' ../Cargo.toml | sed -e 's/upx_version = "\(.*\)"/\1/')
VERSION=$(grep -e '^version =' ../Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
DEB_VERSION=$(echo "$VERSION" | sed -e 's/-/~/g')
if echo "$VERSION" | fgrep -q "-"; then
RPM_VERSION=$(echo "$VERSION" | sed -e 's/-/-0./g')
else
RPM_VERSION="$VERSION-1"
fi
mkdir -p cache/{rpm,deb,musl}
CACHE=$(pwd)/cache
mkdir -p ../dist
docker build --rm -f=Dockerfile-deb --build-arg TOOLCHAIN=$TOOLCHAIN --build-arg UPX_VERSION=$UPX_VERSION -t vpncloud-builder-deb .
# x86_64 deb
if ! [ -f ../dist/vpncloud_${DEB_VERSION}_amd64.deb ]; then
docker_cmd deb 'cd code && cargo deb'
cp $CACHE/deb/target/debian/vpncloud_${DEB_VERSION}_amd64.deb ../dist/vpncloud_${DEB_VERSION}_amd64.deb
fi
build_deb() {
ARCH=$1
TARGET=$2
if ! [ -f ../dist/vpncloud_${DEB_VERSION}_${ARCH}.deb ]; then
docker_cmd deb "cd code && cargo deb --target ${TARGET}"
cp $CACHE/deb/target/${TARGET}/debian/vpncloud_${DEB_VERSION}_${ARCH}.deb ../dist/vpncloud_${DEB_VERSION}_${ARCH}.deb
fi
}
build_deb i386 i686-unknown-linux-gnu
build_deb armhf armv7-unknown-linux-gnueabihf
build_deb armel armv5te-unknown-linux-gnueabi
build_deb arm64 aarch64-unknown-linux-gnu
docker build --rm -f=Dockerfile-musl -t vpncloud-builder-musl .
build_static() {
ARCH=$1
TARGET=$2
if ! [ -f ../dist/vpncloud_${VERSION}_static_${ARCH} ]; then
docker_cmd musl "cd code && cargo build --release --features installer --target ${TARGET} && upx --lzma target/${TARGET}/release/vpncloud"
cp $CACHE/musl/target/${TARGET}/release/vpncloud ../dist/vpncloud_${VERSION}_static_${ARCH}
fi
}
build_static amd64 x86_64-unknown-linux-musl
#build_static i386 i686-unknown-linux-musl
build_static armel armv5te-unknown-linux-musleabi
build_static armhf armv7-unknown-linux-musleabihf
build_static arm64 aarch64-unknown-linux-musl
docker build --rm -f=Dockerfile-rpm -t vpncloud-builder-rpm .
if ! [ -f ../dist/vpncloud_${RPM_VERSION}.x86_64.rpm ]; then
# x86_64 rpm
docker_cmd rpm 'cd code && cargo rpm build'
cp $CACHE/rpm/target/release/rpmbuild/RPMS/x86_64/vpncloud-${RPM_VERSION}.x86_64.rpm ../dist/vpncloud_${RPM_VERSION}.x86_64.rpm
fi
build_rpm() {
ARCH=$1
TARGET=$2
if ! [ -f ../dist/vpncloud_${RPM_VERSION}.${ARCH}.rpm ]; then
mkdir -p $CACHE/rpm/target
[ -L $CACHE/rpm/target/assets ] || ln -s ../assets $CACHE/rpm/target/assets
[ -L $CACHE/rpm/target/target ] || ln -s ../target $CACHE/rpm/target/target
docker_cmd rpm "cd code && cargo rpm build --target ${TARGET}"
cp $CACHE/rpm/target/${TARGET}/release/rpmbuild/RPMS/${ARCH}/vpncloud-${RPM_VERSION}.${ARCH}.rpm ../dist/vpncloud_${RPM_VERSION}.${ARCH}.rpm
fi
}
build_rpm i686 i686-unknown-linux-gnu

196
maskfile.md Normal file
View File

@ -0,0 +1,196 @@
# Commands
Needs [mask](https://github.com/jacobdeichert/mask) to run.
## install-tools
> Install tools.
```sh
set -e
apt-get install -y asciidoctor
cargo install cargo-binstall
cargo binstall cross cargo-deb cargo-generate-rpm
UPX_VERSION=$(grep -e '^upx_version =' Cargo.toml | sed -e 's/upx_version = "\(.*\)"/\1/')
curl https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz -Lf | tar -xJ --strip-components=1 -C /usr/local/bin
```
## manpage
> Generate manpage.
```sh
set -e
echo >&2 "Generating manpage"
if [ ! -f target/vpncloud.1.gz -o vpncloud.adoc -nt target/vpncloud.1.gz ]; then
asciidoctor -b manpage -o target/vpncloud.1 vpncloud.adoc
gzip -f target/vpncloud.1
fi
```
## build-packages-cross (target) (target_name) (target_name_rpm)
> Build the project packages for a given target.
```sh
set -e
VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
TARGET=$target
TARGET_DIR=target/$target_name
# compile
echo >&2 "Compiling for $target_name"
cross build --release --target $TARGET --target-dir $TARGET_DIR
mkdir -p target/$TARGET/release
cp $TARGET_DIR/$TARGET/release/vpncloud target/$TARGET/release/
# build deb
echo >&2 "Building deb package"
cargo deb --no-build --no-strip --target $TARGET
mv target/$TARGET/debian/vpncloud_${VERSION}-1_$target_name.deb dist/vpncloud_${VERSION}_$target_name.deb
# build rpm
if [ -n "$target_name_rpm" ]; then
echo >&2 "Building rpm package"
cargo generate-rpm --target $TARGET --target-dir $TARGET_DIR
mv $TARGET_DIR/$TARGET/generate-rpm/vpncloud-${VERSION}-1.$target_name_rpm.rpm dist/vpncloud_${VERSION}-1.$target_name_rpm.rpm
fi
```
## build-amd64-packages
```sh
$MASK build-packages-cross x86_64-unknown-linux-gnu amd64 x86_64
```
## build-i386-packages
```sh
$MASK build-packages-cross i686-unknown-linux-gnu i386 i686
```
## build-arm64-packages
```sh
$MASK build-packages-cross aarch64-unknown-linux-gnu arm64 aarch64
```
## build-armhf-packages
```sh
$MASK build-packages-cross armv7-unknown-linux-gnueabihf armhf ""
```
## build-armel-packages
```sh
$MASK build-packages-cross armv5te-unknown-linux-gnueabi armel ""
```
## build-static-cross (target) (target_name)
> Build the project statically for a given target.
```sh
set -e
VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
TARGET=$target
TARGET_DIR=target/$target_name-musl
BIN=$TARGET_DIR/$TARGET/release/vpncloud
echo >&2 "Compiling for $target_name musl"
cross build --release --features installer --target $TARGET --target-dir $TARGET_DIR
upx --lzma $BIN
cp $BIN dist/vpncloud_${VERSION}_static_$target_name
```
## build-amd64-static
```sh
$MASK build-static-cross x86_64-unknown-linux-musl amd64
```
## build-i386-static
```sh
$MASK build-static-cross i686-unknown-linux-musl i386
```
## build-arm64-static
```sh
$MASK build-static-cross aarch64-unknown-linux-musl arm64
```
## build-armhf-static
```sh
$MASK build-static-cross armv7-unknown-linux-musleabihf armhf
```
## build-armel-static
```sh
$MASK build-static-cross armv5te-unknown-linux-musleabi armel
```
## build
> Build the project for all architectures.
```sh
set -e
$MASK manpage
$MASK build-amd64-packages
$MASK build-amd64-static
$MASK build-i386-packages
$MASK build-i386-static
$MASK build-arm64-packages
$MASK build-arm64-static
$MASK build-armhf-packages
$MASK build-armhf-static
$MASK build-armel-packages
$MASK build-armel-static
```
## test
> Test the project.
```sh
cargo test --all-features
```
## release
> Release the project.
```sh
set -e
$MASK test
nano Cargo.toml
VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
nano CHANGELOG.md
nano assets/changelog.txt
$MASK build
git commit -a
cargo publish
git tag v$VERSION
git push --tags
```
## count
> Count the lines of code.
```sh
tokei
```