Skip to content
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
71 changes: 60 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: cargo clippy

build-linux:
name: Build Linux
name: Build Linux (x86_64)
runs-on: ubuntu-22.04

steps:
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
mapping[chdig*-x86_64.pkg.tar.zst]=chdig-latest-x86_64.pkg.tar.zst
mapping[chdig*-x86_64.tar.gz]=chdig-latest-x86_64.tar.gz
mapping[chdig*_amd64.deb]=chdig-latest_amd64.deb
mapping[target/chdig]=chdig
mapping[target/chdig]=chdig-amd64
for pattern in "${!mapping[@]}"; do
cp $pattern ${mapping[$pattern]}
done
Expand All @@ -80,12 +80,12 @@ jobs:
sudo dpkg -i chdig-latest_amd64.deb
chdig --help

- name: Archive Linux packages
- name: Archive Packages
uses: actions/upload-artifact@v4
with:
name: linux-packages
name: linux-packages-amd64
path: |
chdig
chdig-amd64
*.deb
*.rpm
*.tar.*
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
ls -al
./chdig-macos-x86_64 --help

- name: Archive MacOS x86_64 packages
- name: Archive Packages
uses: actions/upload-artifact@v4
with:
name: macos-packages-x86_64
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
ls -al
./chdig-macos-arm64 --help

- name: Archive MacOS Arm64 packages
- name: Archive Packages
uses: actions/upload-artifact@v4
with:
name: macos-packages-arm64
Expand Down Expand Up @@ -232,11 +232,60 @@ jobs:
run: |
make deploy-binary
cp target/chdig.exe chdig-windows.exe
Compress-Archive -Path chdig-windows.exe -DestinationPath chdig-windows.exe.zip
Compress-Archive -Path chdig-windows.exe -DestinationPath chdig-windows-x86_64.exe.zip

- name: Archive Windows packages
- name: Archive Packages
uses: actions/upload-artifact@v4
with:
name: windows-packages
name: windows-packages-x86_64
path: |
chdig-windows.exe.zip
chdig-windows-x86_64.exe.zip

build-linux-aarch64:
name: Build Linux (aarch64)
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
with:
# To fetch tags, but can this be improved using blobless checkout?
# [1]. But anyway right it is not important, and unlikely will be,
# since the repository is small.
#
# [1]: https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/
fetch-depth: 0
persist-credentials: false

# Workaround for https://github.com/actions/checkout/issues/882
- name: Fix tags for release
# will break on a lightweight tag
run: git fetch origin +refs/tags/*:refs/tags/*

- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Install dependencies
run: |
curl -sS -Lo /tmp/nfpm.deb "https://github.com/goreleaser/nfpm/releases/download/v2.25.0/nfpm_amd64.deb" && sudo dpkg -i /tmp/nfpm.deb
cc --version
gcc_version=$(readlink -f $(which cc) | awk -F- '{print $NF}')
sudo apt-get install -y libc6-dev-arm64-cross libstdc++-$gcc_version-dev-arm64-cross
rustup target add aarch64-unknown-linux-musl

- name: Build
run: |
set -x
# NOTE: for non-native target we cannot build packages, since they
# requires bash_completion, which requires chdig execution
#
# But we can try cross (that uses qemu for this).
make deploy-binary target=aarch64-unknown-linux-musl
cp target/chdig chdig-aarch64

- name: Archive Packages
uses: actions/upload-artifact@v4
with:
name: linux-packages-aarch64
path: |
chdig-aarch64
12 changes: 5 additions & 7 deletions .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ jobs:
automatic_release_tag: "latest"
title: "Development Build"
files: |
macos-packages-x86_64/chdig-macos-x86_64.gz
macos-packages-arm64/chdig-macos-arm64.gz
windows-packages/chdig-windows.exe.zip
linux-packages/chdig
linux-packages/*.deb
linux-packages/*.rpm
linux-packages/*.tar.*
macos-packages-x86_64/*
macos-packages-arm64/*
windows-packages-x86_64/*
linux-packages-amd64/*
linux-packages-aarch64/*
12 changes: 5 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ jobs:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
macos-packages-x86_64/chdig-macos-x86_64.gz
macos-packages-arm64/chdig-macos-arm64.gz
windows-packages/chdig-windows.exe.zip
linux-packages/chdig
linux-packages/*.deb
linux-packages/*.rpm
linux-packages/*.tar.*
macos-packages-x86_64/*
macos-packages-arm64/*
windows-packages-x86_64/*
linux-packages-amd64/*
linux-packages-aarch64/*
64 changes: 59 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# FIXME: rewrite with build.rs

debug ?=
target ?= $(shell rustc -vV | sed -n 's|host: ||p')
arch = $(shell uname -m)
# Parse the target (i.e. aarch64-unknown-linux-musl)
target_os := $(shell echo $(target) | cut -d'-' -f3)
target_libc := $(shell echo $(target) | cut -d'-' -f4)
target_arch := $(shell echo $(target) | cut -d'-' -f1)
host_arch := $(shell uname -m)

# Version normalization for deb/rpm:
# - trim "v" prefix
Expand All @@ -19,6 +21,7 @@ $(info CHDIG_VERSION = $(CHDIG_VERSION))
$(info CHDIG_VERSION_ARCH = $(CHDIG_VERSION_ARCH))
$(info debug = $(debug))
$(info target = $(target))
$(info host_arch = $(host_arch))

ifdef debug
cargo_build_opts :=
Expand All @@ -29,7 +32,58 @@ else
endif

ifneq ($(target),)
cargo_build_opts += --target $(target)
cargo_build_opts += --target $(target)
endif

# Normalize architecture names
norm_target_arch := $(shell echo $(target_arch) | sed -e 's/^aarch64$$/arm64/' -e 's/^x86_64$$/amd64/')
norm_host_arch := $(shell echo $(host_arch) | sed -e 's/^aarch64$$/arm64/' -e 's/^x86_64$$/amd64/')

$(info Normalized target arch: $(norm_target_arch))
$(info Normalized host arch: $(norm_host_arch))

# Cross compilation requires some tricks:
# - use lld linker
# - explicitly specify path for libstdc++
# (Also some packages, that you can found in github actions manifests)
#
# TODO: allow to use clang/gcc from PATH
ifneq ($(norm_host_arch),$(norm_target_arch))
$(info Cross compilation for $(target_arch))

# Detect the latest lld
LLD := $(shell ls /usr/bin/ld.lld /usr/bin/ld.lld-* 2>/dev/null | sort -V | tail -n1)
$(info LLD = $(LLD))
# Detect the latest clang
CLANG := $(shell ls /usr/bin/clang /usr/bin/clang-* 2>/dev/null | grep -e '/clang$$' -e '/clang-[0-9]\+$$' | sort -V | tail -n1)
$(info CLANG = $(CLANG))
CLANG_CXX := $(shell ls /usr/bin/clang++ /usr/bin/clang++-* 2>/dev/null | grep -e '/clang++$$' -e '/clang++-[0-9]\+$$' | sort -V | tail -n1)
$(info CLANG_CXX = $(CLANG_CXX))

export CC := $(CLANG)
export CXX := $(CLANG_CXX)
export RUSTFLAGS := -C linker=$(LLD)

# /usr/aarch64-linux-gnu/lib64/ (archlinux aarch64-linux-gnu-gcc)
prefix := /usr/$(target_arch)-$(target_os)-gnu/lib
ifneq ($(wildcard $(prefix)),)
export RUSTFLAGS := $(RUSTFLAGS) -C link-args=-L$(prefix)
endif
prefix := /usr/$(target_arch)-$(target_os)-gnu/lib64
ifneq ($(wildcard $(prefix)),)
export RUSTFLAGS := $(RUSTFLAGS) -C link-args=-L$(prefix)
endif

# /usr/lib/gcc-cross/aarch64-linux-gnu/$gcc (ubuntu)
latest_gcc_cross_version := $(shell ls -d /usr/lib/gcc-cross/$(target_arch)-$(target_os)-gnu/* 2>/dev/null | sort -V | tail -n1 | xargs -I{} basename {})
prefix := /usr/lib/gcc-cross/$(target_arch)-$(target_os)-gnu/$(latest_gcc_cross_version)
ifneq ($(wildcard $(prefix)),)
export RUSTFLAGS := $(RUSTFLAGS) -C link-args=-L$(prefix)
endif

# NOTE: there is also https://musl.cc/aarch64-linux-musl-cross.tgz

$(info RUSTFLAGS = $(RUSTFLAGS))
endif

.PHONY: build build_completion deploy-binary chdig install run \
Expand Down Expand Up @@ -73,7 +127,7 @@ tar: archlinux
tar -C $$tmp_dir -vxf chdig-${CHDIG_VERSION_ARCH}-1-x86_64.pkg.tar.zst usr
# Strip /tmp/chdig-${CHDIG_VERSION}.XXXXXX and replace it with chdig-${CHDIG_VERSION}
# (and we need to remove leading slash)
tar --show-transformed-names --transform "s#^$${tmp_dir#/}#chdig-${CHDIG_VERSION}-${arch}#" -vczf chdig-${CHDIG_VERSION}-${arch}.tar.gz $$tmp_dir
tar --show-transformed-names --transform "s#^$${tmp_dir#/}#chdig-${CHDIG_VERSION}-${target_arch}#" -vczf chdig-${CHDIG_VERSION}-${target_arch}.tar.gz $$tmp_dir
echo rm -fr $$tmp_dir

help:
Expand Down