Skip to content
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

cargo zigbuild #799

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
135896a
zig-release
phoepsilonix Jan 23, 2024
0c71660
Merge branch 'raphlinus:master' into zig-release
phoepsilonix Jan 28, 2024
24f9fb1
Merge branch 'raphlinus:master' into zig-release
phoepsilonix Jan 31, 2024
ee2fdda
Merge branch 'raphlinus:master' into zig-release
phoepsilonix Feb 2, 2024
11dc325
branch_0.9.3 v0.9.6
phoepsilonix Feb 2, 2024
f6008ac
Merge branch 'raphlinus:master' into zig-release
phoepsilonix Feb 3, 2024
41f3c6a
v0.10.0
phoepsilonix Feb 3, 2024
fc1269e
git pull upstream --tags
phoepsilonix Feb 3, 2024
a5b17ec
workflow
phoepsilonix Feb 3, 2024
16a2b16
v0.9.6
phoepsilonix Feb 3, 2024
aba1f68
release
phoepsilonix Feb 4, 2024
b5c8f9a
Merge branch 'raphlinus:master' into zig-release
phoepsilonix Feb 8, 2024
caca086
tag and commit
phoepsilonix Feb 8, 2024
13b3ff0
tag and commit
phoepsilonix Feb 8, 2024
686906a
Merge branch 'zig-release' of github.com:phoepsilonix/pulldown-cmark …
phoepsilonix Feb 28, 2024
11e3ead
ziglang update dev.3076
phoepsilonix Feb 29, 2024
deaa2cd
remove cargo update
phoepsilonix Feb 29, 2024
b170516
install binutils-mingw-w64
phoepsilonix Feb 29, 2024
ae550c3
update zigland 0.11.0
phoepsilonix Feb 29, 2024
602a44f
modified version
phoepsilonix Feb 29, 2024
561a517
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Mar 3, 2024
ae42808
fix version.txt
phoepsilonix Mar 3, 2024
b3ab681
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Mar 3, 2024
d15af09
tag -> version
phoepsilonix Mar 3, 2024
5c573db
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Mar 3, 2024
9d9f734
mold 2.4.1,sccache 0.7.7
phoepsilonix Mar 4, 2024
f77d6c2
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Mar 6, 2024
8e4e0df
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Mar 16, 2024
baffc5e
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Mar 17, 2024
b4841a3
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Apr 1, 2024
7c42e35
mold update
phoepsilonix Apr 1, 2024
b0adc4e
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Apr 4, 2024
3327b72
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Apr 5, 2024
119fc64
tag fix
phoepsilonix Apr 5, 2024
79094b0
Fine-tuning tags
phoepsilonix Apr 12, 2024
3c69820
sccache update
phoepsilonix Apr 12, 2024
e8fd7bf
submodule is no needed
phoepsilonix Apr 13, 2024
17cbb2b
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Apr 16, 2024
a5c0f2e
tag flow
phoepsilonix Apr 16, 2024
7c1c390
disable rust workflow
phoepsilonix Apr 16, 2024
b168d71
.gitignore
phoepsilonix Apr 16, 2024
83885d4
tag flow fix
phoepsilonix Apr 16, 2024
e955c1e
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Apr 20, 2024
460c50f
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix Apr 23, 2024
ae118e9
version tag fix
phoepsilonix Apr 23, 2024
48d00b0
Merge branch 'pulldown-cmark:master' into zig-release
phoepsilonix May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
138 changes: 138 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Release

on:
push:
tags:
- 'v*'
- 'commit-*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
env:
SCCACHE_CACHE_SIZE: 1G
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
SCCACHE_DIR: /home/runner/.cache/sccache
# SCCACHE_RECACHE: 1 # Uncomment this to clear cache, then comment
steps:
- uses: actions/checkout@v4
with:
lfs: true
path: zig-release
- name: Setup variables
id: variables
run: |
VER=${GITHUB_REF##*/}
VER=${VER#commit-}
VER=${VER%-release}
echo "version=${VER}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
lfs: true
path: pulldown-cmark
- name: checkout tag
run: |
cd zig-release
TAG=${GITHUB_REF##*/}
git fetch --prune --unshallow --tags --no-recurse-submodules --filter=tree:0
if [[ "$TAG" =~ ^commit- ]]; then
COMMIT=$(git log -1 ${TAG#commit-} --pretty=%h)
echo $TAG
git tag $TAG -d
git push origin $TAG -d
base_tag=$(git describe --tags --abbrev=0 --always ${COMMIT})
echo $base_tag
base_tag=${base_tag/+*/}
echo $base_tag
COUNT=$(($(git rev-list --count $COMMIT)-$(git rev-list --count $base_tag)))
if [[ $COUNT != 0 ]];then
TAG=$base_tag-$COUNT-g$COMMIT
else
TAG=$base_tag
fi
echo "tag_name=" $TAG
echo $TAG
echo "tag_name=${TAG}" >> $GITHUB_OUTPUT
echo "tag_commit=$(git log -1 --pretty=%H $TAG)" >> $GITHUB_OUTPUT
else
TAG=${{ steps.variables.outputs.version }}
echo "tag_name=$(git describe --tags --always $TAG)" >> $GITHUB_OUTPUT
echo "tag_commit=$(git log -1 --pretty=%H $TAG)" >> $GITHUB_OUTPUT
fi
cd ../pulldown-cmark
echo $TAG | sed -e 's/-g.*$//g' -e 's/-/+/g' > version.txt
cat version.txt
- name: Generate release tag
id: release_tag
run: |
echo "release_tag=$(cat pulldown-cmark/version.txt)" >> $GITHUB_OUTPUT
- name: Generate release note
id: release_note
run: |
{
echo "release_note<<EOF"
echo "$(cd zig-release && git log --pretty=format:"%C(yellow)commit %H%C(auto)%d%nAuthor: %an%nDate: %ad%n%n%s%n%n%b" -1 ${{ steps.variables.outputs.version }})"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: test
run: |
echo "1: ${{ steps.release_tag.outputs.release_tag }}"
echo "2: ${{ steps.release_note.outputs.release_note }}"
- name: copy Makefile for zig-release
run: |
mkdir -p source
cd pulldown-cmark
cd ../zig-release
cp Makefile archive.sh target.txt ../pulldown-cmark/
cp config.toml target.txt ../
- name: install zig and tools (Linux)
run: |
#pacman -Sy sudo rustup clang llvm lld make git --noconfirm
sudo apt-get install build-essential make git clang binutils-mingw-w64 wget
rm -f ~/.cargo/config*
mkdir -p zig
curl -LZ https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz|tar xJ --strip-component=1 -C zig
sudo mv zig /usr/local/
echo "/usr/local/zig" >> $GITHUB_PATH
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.4
with:
version: "v0.7.7"
- name: Install mold linker
uses: rui314/setup-mold@staging
with:
mold-version: 2.30.0
make-default: true
- name: Cache toolchain
uses: Swatinem/rust-cache@v2
- name: Update toolchain
run: |
rustup update nightly
rustup default nightly
rustup component add rust-src
rustup target add $(cat target.txt)
rustup +stable target add $(cat target.txt)
- name: Install cargo-zigbuild
run: |
cargo install cargo-zigbuild --target x86_64-unknown-linux-gnu
- name: config.toml
run: |
mkdir -p ~/.cargo/
rm -f ~/.cargo/config*
cp config.toml ~/.cargo/config.toml
- name: Build and archive
shell: bash
run: |
cd pulldown-cmark
make target-archive
- name: Create release
uses: ncipollo/release-action@v1
with:
tag: "${{ steps.release_tag.outputs.release_tag }}"
name: "${{ steps.release_tag.outputs.release_tag }}"
artifacts: 'pulldown-cmark/release/*'
token: ${{ secrets.GITHUB_TOKEN }}
body: "${{ steps.release_note.outputs.release_note }}"

37 changes: 0 additions & 37 deletions .github/workflows/rust.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target

.github/workflows/rust.yml
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TARGET=$(shell cat target.txt)

.PHONY: lint
lint:
@cargo +nightly clippy

.PHONY: fix
fix:
@cargo +nightly clippy --fix

.PHONY: test
test:
@cargo +nightly test

.PHONY: shellspec
shellspec:
@shellspec

.PHONY: install
install:
@cargo +nightly install --path .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what the goal is there but none of this smell right. As someone packaging this for distros and using it myself, this whole pile of changes would just confuse me about how the project was expected to be used. It doesn't need +nightly. This Makefile is a thin wrapper around other commands and doesn't support any of the tooling I'd expect an actual Makefile to handle. Most of this feels more like it should go in a Justfile or something for developer jobs, but most of it isn't even build stuff, and the bits that are don't seem to be general purpose.


.PHONY: check
check:
@cargo +nightly check

.PHONY: target-add
target-add:
@rustup override set nightly
@rustup target add $(TARGET)

.PHONY: target-build
target-build: target-add
@for target in $(TARGET); do echo $$target; cargo +nightly zigbuild --release --target $$target || cargo +stable zigbuild --release --target $$target; done

.PHONY: target-archive
target-archive: target-build
@bash archive.sh $(TARGET)
22 changes: 22 additions & 0 deletions archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
version=$(cat version.txt)
if [[ "${version}" == "" ]]; then
echo "cannot get version tag from HEAD commit"
exit 1
fi
bin=$(basename "$(git rev-parse --show-toplevel)")
target="$*"

if [[ ! -d "release" ]]; then
mkdir "release"
fi

for target in "$@"; do
archive="${bin}_${version}_${target}"
echo "## make archive ${archive}"
if [[ "$target" == *"windows"* ]]; then
( cd "target/${target}/release/" && zip "../../../release/${archive}.zip" "${bin}.exe" )
else
( cd "target/${target}/release/" && tar -Jcvf "../../../release/${archive}.tar.xz" "${bin}" )
fi
done
64 changes: 64 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[build]
target = "x86_64-unknown-linux-musl"
rustc-wrapper = "sccache"

[unstable]
build-std = ["core", "compiler_builtins", "alloc", "std", "panic_abort"]
build-std-features = ["llvm-libunwind"]

[target.x86_64-unknown-linux-musl]
linker = "clang"
rustflags = [
"-Clink-self-contained=on",
"-C", "strip=symbols",
"-C", "no-redzone=y",
"-C", "overflow-checks=y",
"-C", "lto=fat",
"-C", "embed-bitcode=y",
"-C", "codegen-units=1",
"-C", "opt-level=z",
"-C", "control-flow-guard=y",
"-C", "link-args=-fuse-ld=mold -Wp,-D_FORTIFY_SOURCE=2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIE -fpie -Wl,-z,relro,-z,now",
]

[target.x86_64-pc-windows-gnu]
linker = "clang"
rustflags = [
"-C", "strip=symbols",
"-C", "no-redzone=y",
"-C", "overflow-checks=y",
"-C", "lto=fat",
"-C", "embed-bitcode=y",
"-C", "codegen-units=1",
"-C", "opt-level=z",
"-C", "control-flow-guard=y",
"-C", "link-args=-fuse-ld=mold -Wp,-D_FORTIFY_SOURCE=2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIE -fpie -Wl,-z,relro,-z,now",
]

[target.x86_64-apple-darwin]
linker = "clang"
rustflags = [
"-C", "strip=symbols",
"-C", "no-redzone=y",
"-C", "overflow-checks=y",
"-C", "lto=fat",
"-C", "embed-bitcode=y",
"-C", "codegen-units=1",
"-C", "opt-level=z",
"-C", "control-flow-guard=y",
"-C", "link-args=-fuse-ld=mold -Wp,-D_FORTIFY_SOURCE=2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIE -fpie -Wl,-z,relro,-z,now",
]

[target.aarch64-apple-darwin]
linker = "clang"
rustflags = [
"-C", "strip=symbols",
"-C", "no-redzone=y",
"-C", "overflow-checks=y",
"-C", "lto=fat",
"-C", "embed-bitcode=y",
"-C", "codegen-units=1",
"-C", "opt-level=z",
"-C", "control-flow-guard=y",
"-C", "link-args=-fuse-ld=mold -Wp,-D_FORTIFY_SOURCE=2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIE -fpie -Wl,-z,relro,-z,now",
]
4 changes: 4 additions & 0 deletions target.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x86_64-unknown-linux-musl
x86_64-pc-windows-gnu
x86_64-apple-darwin
aarch64-apple-darwin