From 8fdd1e67112bb5412bd476cfbbd001307111eb06 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 28 May 2026 16:24:45 +0300 Subject: [PATCH] ci: add scheduled tccbin updates --- .github/workflows/update_tccbin.yml | 216 ++++++++++++++++++ .../thirdparty-freebsd-amd64_tcc.sh | 10 +- .../thirdparty-linux-amd64_tcc.sh | 10 +- .../thirdparty-macos-amd64_tcc.sh | 114 +++++++++ .../thirdparty-macos-arm64_tcc.sh | 10 +- .../thirdparty-openbsd-amd64_tcc.sh | 9 +- 6 files changed, 358 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/update_tccbin.yml create mode 100755 thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh diff --git a/.github/workflows/update_tccbin.yml b/.github/workflows/update_tccbin.yml new file mode 100644 index 000000000..40559d80c --- /dev/null +++ b/.github/workflows/update_tccbin.yml @@ -0,0 +1,216 @@ +name: Update tccbin + +on: + workflow_dispatch: + inputs: + tcc_commit: + description: 'TinyCC ref, branch, or commit to build' + required: false + default: mob + publish: + description: 'Push the rebuilt bundle to vlang/tccbin' + type: boolean + required: false + default: false + force_rebuild: + description: 'Rebuild even when tccbin already records the same TinyCC hash' + type: boolean + required: false + default: false + schedule: + - cron: '17 3 1 * *' + +permissions: + contents: read + +concurrency: + group: update-tccbin-${{ github.ref }} + cancel-in-progress: false + +jobs: + update-tccbin-hosted: + if: github.repository == 'vlang/v' && (github.event_name != 'schedule' || github.ref == 'refs/heads/master') + strategy: + fail-fast: false + matrix: + include: + - id: linux-amd64 + os: ubuntu-latest + branch: thirdparty-linux-amd64 + script: thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh + - id: macos-amd64 + os: macos-15-intel + branch: thirdparty-macos-amd64 + script: thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh + - id: macos-arm64 + os: macos-latest + branch: thirdparty-macos-arm64 + script: thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh + runs-on: ${{ matrix.os }} + env: + TCC_COMMIT: ${{ github.event.inputs.tcc_commit || 'mob' }} + TCCBIN_REPO: vlang/tccbin + PUBLISH: ${{ github.event_name == 'schedule' || github.event.inputs.publish == 'true' }} + FORCE_REBUILD: ${{ github.event.inputs.force_rebuild == 'true' }} + steps: + - uses: actions/checkout@v6 + + - name: Install macOS build dependencies + if: runner.os == 'macOS' + run: brew install make + + - name: Resolve TinyCC source hash + id: tinycc + shell: bash + run: | + set -euo pipefail + git clone --quiet https://repo.or.cz/tinycc.git /tmp/tinycc-ref + git -C /tmp/tinycc-ref checkout --quiet "$TCC_COMMIT" + hash="$(git -C /tmp/tinycc-ref rev-parse HEAD)" + echo "hash=$hash" >> "$GITHUB_OUTPUT" + echo "TinyCC $TCC_COMMIT resolves to $hash" + + - name: Clone tccbin branch + shell: bash + env: + TCCBIN_TOKEN: ${{ secrets.VLANG_BOT_SECRET }} + run: | + set -euo pipefail + git clone --branch "${{ matrix.branch }}" --depth=1 \ + "https://github.com/${TCCBIN_REPO}.git" thirdparty/tcc + if [ "$PUBLISH" = 'true' ]; then + if [ -z "$TCCBIN_TOKEN" ]; then + echo "::error::VLANG_BOT_SECRET is required to publish to ${TCCBIN_REPO}" + exit 1 + fi + git -C thirdparty/tcc remote set-url origin \ + "https://vlang-bot:${TCCBIN_TOKEN}@github.com/${TCCBIN_REPO}.git" + fi + + - name: Check whether rebuild is needed + id: rebuild + shell: bash + run: | + set -euo pipefail + if [ "$FORCE_REBUILD" != 'true' ] \ + && [ -f thirdparty/tcc/build_source_hash.txt ] \ + && [ "$(cat thirdparty/tcc/build_source_hash.txt)" = "${{ steps.tinycc.outputs.hash }}" ]; then + echo "skip=true" >> "$GITHUB_OUTPUT" + echo "tccbin/${{ matrix.branch }} already has TinyCC ${{ steps.tinycc.outputs.hash }}" + else + echo "skip=false" >> "$GITHUB_OUTPUT" + fi + + - name: Configure git identity + if: steps.rebuild.outputs.skip != 'true' + run: | + git config --global user.name vlang-bot + git config --global user.email vlang-bot@users.noreply.github.com + + - name: Build TCC bundle + if: steps.rebuild.outputs.skip != 'true' + shell: bash + env: + BUILD_CMD: TCC_COMMIT=${{ env.TCC_COMMIT }} TCC_FOLDER=thirdparty/tcc bash ${{ matrix.script }} + run: | + set -euo pipefail + TCC_FOLDER=thirdparty/tcc bash "${{ matrix.script }}" + test "$(cat thirdparty/tcc/build_source_hash.txt)" = "${{ steps.tinycc.outputs.hash }}" + thirdparty/tcc/tcc.exe --version + thirdparty/tcc/tcc.exe -v -v + + - name: Upload TCC bundle artifact + if: steps.rebuild.outputs.skip != 'true' + uses: actions/upload-artifact@v7 + with: + name: tccbin-${{ matrix.id }} + path: thirdparty/tcc + + - name: Push tccbin branch + if: steps.rebuild.outputs.skip != 'true' && env.PUBLISH == 'true' + shell: bash + run: | + set -euo pipefail + git -C thirdparty/tcc push origin HEAD:${{ matrix.branch }} + + update-tccbin-bsd: + if: github.repository == 'vlang/v' && (github.event_name != 'schedule' || github.ref == 'refs/heads/master') + strategy: + fail-fast: false + matrix: + include: + - id: freebsd-amd64 + operating_system: freebsd + version: '15.0' + branch: thirdparty-freebsd-amd64 + script: thirdparty/build_scripts/thirdparty-freebsd-amd64_tcc.sh + install: sudo pkg install -y bash git gmake rsync + cc: cc + - id: openbsd-amd64 + operating_system: openbsd + version: '7.8' + branch: thirdparty-openbsd-amd64 + script: thirdparty/build_scripts/thirdparty-openbsd-amd64_tcc.sh + install: sudo pkg_add bash git gmake rsync + cc: clang + runs-on: ubuntu-latest + env: + TCC_COMMIT: ${{ github.event.inputs.tcc_commit || 'mob' }} + TCCBIN_REPO: vlang/tccbin + PUBLISH: ${{ github.event_name == 'schedule' || github.event.inputs.publish == 'true' }} + FORCE_REBUILD: ${{ github.event.inputs.force_rebuild == 'true' }} + TCCBIN_TOKEN: ${{ secrets.VLANG_BOT_SECRET }} + steps: + - uses: actions/checkout@v6 + + - name: Start ${{ matrix.id }} VM + uses: cross-platform-actions/action@v1.1.0 + with: + operating_system: ${{ matrix.operating_system }} + version: ${{ matrix.version }} + memory: 4G + shell: sh + sync_files: runner-to-vm + environment_variables: TCC_COMMIT TCCBIN_REPO PUBLISH FORCE_REBUILD TCCBIN_TOKEN + + - name: Build and publish ${{ matrix.id }} TCC bundle + shell: cpa.sh {0} + run: | + set -eu + ${{ matrix.install }} + git config --global user.name vlang-bot + git config --global user.email vlang-bot@users.noreply.github.com + git config --global --add safe.directory "$PWD" + + git clone --quiet https://repo.or.cz/tinycc.git /tmp/tinycc-ref + git -C /tmp/tinycc-ref checkout --quiet "$TCC_COMMIT" + tinycc_hash="$(git -C /tmp/tinycc-ref rev-parse HEAD)" + echo "TinyCC $TCC_COMMIT resolves to $tinycc_hash" + + git clone --branch "${{ matrix.branch }}" --depth=1 \ + "https://github.com/${TCCBIN_REPO}.git" thirdparty/tcc + if [ "$PUBLISH" = 'true' ]; then + if [ -z "$TCCBIN_TOKEN" ]; then + echo "VLANG_BOT_SECRET is required to publish to ${TCCBIN_REPO}" >&2 + exit 1 + fi + git -C thirdparty/tcc remote set-url origin \ + "https://vlang-bot:${TCCBIN_TOKEN}@github.com/${TCCBIN_REPO}.git" + fi + + if [ "$FORCE_REBUILD" != 'true' ] \ + && [ -f thirdparty/tcc/build_source_hash.txt ] \ + && [ "$(cat thirdparty/tcc/build_source_hash.txt)" = "$tinycc_hash" ]; then + echo "tccbin/${{ matrix.branch }} already has TinyCC $tinycc_hash" + exit 0 + fi + + BUILD_CMD="TCC_COMMIT=$TCC_COMMIT TCC_FOLDER=thirdparty/tcc CC=${{ matrix.cc }} bash ${{ matrix.script }}" \ + TCC_FOLDER=thirdparty/tcc CC="${{ matrix.cc }}" bash "${{ matrix.script }}" + test "$(cat thirdparty/tcc/build_source_hash.txt)" = "$tinycc_hash" + thirdparty/tcc/tcc.exe --version + thirdparty/tcc/tcc.exe -v -v + + if [ "$PUBLISH" = 'true' ]; then + git -C thirdparty/tcc push origin HEAD:${{ matrix.branch }} + fi diff --git a/thirdparty/build_scripts/thirdparty-freebsd-amd64_tcc.sh b/thirdparty/build_scripts/thirdparty-freebsd-amd64_tcc.sh index aa1012462..d00828d3f 100755 --- a/thirdparty/build_scripts/thirdparty-freebsd-amd64_tcc.sh +++ b/thirdparty/build_scripts/thirdparty-freebsd-amd64_tcc.sh @@ -10,9 +10,14 @@ ## OF REBUILDING, FOR EASIER/RELIABLE REPRODUCTION OF HISTORIC VERSIONS. ## IT IS NOT INTENDED TO BE MODIFIED. -BUILD_CMD=`fc -nl -0` +if test -z "$BUILD_CMD"; then + BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" +fi ## remove whitespaces before/after the actual command: BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +if test -z "$BUILD_CMD"; then + BUILD_CMD="$0" +fi set -e @@ -41,7 +46,7 @@ rsync -a thirdparty/tcc/ thirdparty/tcc.original/ pushd . -git clone git://repo.or.cz/tinycc.git +git clone https://repo.or.cz/tinycc.git cd tinycc @@ -91,4 +96,3 @@ popd echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH ." echo "The tcc executable is ready in $TCC_FOLDER/tcc.exe" - diff --git a/thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh b/thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh index 0f38542b4..15f2ab6da 100755 --- a/thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh +++ b/thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh @@ -10,9 +10,14 @@ ## OF REBUILDING, FOR EASIER/RELIABLE REPRODUCTION OF HISTORIC VERSIONS. ## IT IS NOT INTENDED TO BE MODIFIED. -BUILD_CMD=`fc -nl -0` +if test -z "$BUILD_CMD"; then + BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" +fi ## remove whitespaces before/after the actual command: BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +if test -z "$BUILD_CMD"; then + BUILD_CMD="$0" +fi set -e @@ -40,7 +45,7 @@ rsync -a thirdparty/tcc/ thirdparty/tcc.original/ pushd . -git clone git://repo.or.cz/tinycc.git +git clone https://repo.or.cz/tinycc.git cd tinycc @@ -91,4 +96,3 @@ git commit -m "build with \`$BUILD_CMD\`" popd echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH . The tcc executable is ready in $TCC_FOLDER/tcc.exe " - diff --git a/thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh b/thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh new file mode 100755 index 000000000..edfc773d2 --- /dev/null +++ b/thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh @@ -0,0 +1,114 @@ +## NOTE: this script does *not* use a shebang **deliberately**, in order to +## access the same shell, to capture its own launching command with `fc`, +## and to record it later in the new commit message in thirdpart/tcc. + +## WARNING: THE ORIGINAL OF THIS SCRIPT IS IN: +## https://github.com/vlang/v/blob/master/thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh , +## I.E. IN THE MAIN V REPOSITORY. IF YOU NEED TO MAKE CHANGES, CHANGE THAT. +## +## THE `build.sh` FILE IN `vlang/tccbin` REPO IS A COPY, RECORDED AT THE TIME +## OF REBUILDING, FOR EASIER/RELIABLE REPRODUCTION OF HISTORIC VERSIONS. +## IT IS NOT INTENDED TO BE MODIFIED. + + +if test -z "$BUILD_CMD"; then + BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" +fi +## remove whitespaces before/after the actual command: +BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +if test -z "$BUILD_CMD"; then + BUILD_CMD="$0" +fi + +set -e + +## make sure that commands use English in their output, instead of the local system's local: +export LANG=C + +if ! test -f vlib/v/compiler_errors_test.v; then + echo "this script should be run in V's main repo folder!" + exit 1 +fi + +export CFLAGS='-O3' +export CURRENT_SCRIPT_PATH=$(realpath "$0") + +export TCC_COMMIT="${TCC_COMMIT:-mob}" +export TCC_FOLDER="${TCC_FOLDER:-thirdparty/tcc.$TCC_COMMIT}" +export CC="${CC:-clang}" + +echo " BUILD_CMD: \`$BUILD_CMD\`" +echo " CC: $CC" +echo "TCC_COMMIT: $TCC_COMMIT" +echo "TCC_FOLDER: \`$TCC_FOLDER\`" +echo =============================================================== + +rm -rf tinycc/ +rm -rf thirdparty/tcc.original/ +rsync -a thirdparty/tcc/ thirdparty/tcc.original/ +## rm -rf $TCC_FOLDER + +pushd . + +git clone https://repo.or.cz/tinycc.git + +cd tinycc + +git checkout $TCC_COMMIT +export TCC_COMMIT_FULL_HASH=$(git rev-parse HEAD) + +### NB: the symlinks below are needed, to ensure proper support for bootstrapping tcc, otherwise backtraces will be disabled . +for i in include/*.h; do echo $i; ln -s $i $(basename $i); done + +# --libdir=$TCC_FOLDER/lib \ + +./configure \ + --prefix=$TCC_FOLDER \ + --bindir=$TCC_FOLDER \ + --tccdir=$TCC_FOLDER/lib \ + --includedir=$TCC_FOLDER/include \ + --crtprefix=$TCC_FOLDER/lib:/usr/lib \ + --sysincludepaths=$TCC_FOLDER/include:$TCC_FOLDER/lib/include:/usr/local/include:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \ + --libpaths=$TCC_FOLDER/lib:/usr/local/lib:/usr/lib:/lib \ + --config-new_macho=yes \ + --config-codesign \ + --cc="$CC" \ + --extra-cflags="$CFLAGS" \ + --config-bcheck=yes \ + --config-backtrace=yes \ + --enable-static \ + --dwarf=5 \ + --debug + +gmake +gmake install + +popd + +rsync -a --delete tinycc/$TCC_FOLDER/* $TCC_FOLDER/ +rsync -a thirdparty/tcc.original/.git/ $TCC_FOLDER/.git/ +rsync -a thirdparty/tcc.original/lib/libgc* $TCC_FOLDER/lib/ +rsync -a thirdparty/tcc.original/lib/build* $TCC_FOLDER/lib/ +rsync -a thirdparty/tcc.original/README.md $TCC_FOLDER/README.md +rsync -a $CURRENT_SCRIPT_PATH $TCC_FOLDER/build.sh +mv $TCC_FOLDER/tcc $TCC_FOLDER/tcc.exe + +date > $TCC_FOLDER/build_on_date.txt +echo $TCC_COMMIT_FULL_HASH > $TCC_FOLDER/build_source_hash.txt +$TCC_FOLDER/tcc.exe --version > $TCC_FOLDER/build_version.txt +uname -a > $TCC_FOLDER/build_machine_uname.txt + +## needed for Big Sur +ln -s /System/DriverKit/usr/lib/libSystem.dylib $TCC_FOLDER/lib/libc.dylib + +## show the builtin search paths for sanity checking: +$TCC_FOLDER/tcc.exe -v -v + +pushd . +cd $TCC_FOLDER +git add . +git commit -m "build with \`$BUILD_CMD\`" +popd + +echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH ." +echo "The tcc executable is ready in $TCC_FOLDER/tcc.exe" diff --git a/thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh b/thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh index 6c88bc175..37226ce03 100755 --- a/thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh +++ b/thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh @@ -11,9 +11,14 @@ ## IT IS NOT INTENDED TO BE MODIFIED. -BUILD_CMD=`fc -nl -0` +if test -z "$BUILD_CMD"; then + BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" +fi ## remove whitespaces before/after the actual command: BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +if test -z "$BUILD_CMD"; then + BUILD_CMD="$0" +fi set -e @@ -45,7 +50,7 @@ rsync -a thirdparty/tcc/ thirdparty/tcc.original/ pushd . -git clone git://repo.or.cz/tinycc.git +git clone https://repo.or.cz/tinycc.git cd tinycc @@ -107,4 +112,3 @@ popd echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH ." echo "The tcc executable is ready in $TCC_FOLDER/tcc.exe" - diff --git a/thirdparty/build_scripts/thirdparty-openbsd-amd64_tcc.sh b/thirdparty/build_scripts/thirdparty-openbsd-amd64_tcc.sh index d9ca94f99..0bb4f25e8 100755 --- a/thirdparty/build_scripts/thirdparty-openbsd-amd64_tcc.sh +++ b/thirdparty/build_scripts/thirdparty-openbsd-amd64_tcc.sh @@ -10,9 +10,14 @@ ## OF REBUILDING, FOR EASIER/RELIABLE REPRODUCTION OF HISTORIC VERSIONS. ## IT IS NOT INTENDED TO BE MODIFIED. -BUILD_CMD=`fc -nl -0` +if test -z "$BUILD_CMD"; then + BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" +fi ## remove whitespaces before/after the actual command: BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" +if test -z "$BUILD_CMD"; then + BUILD_CMD="$0" +fi set -e @@ -40,7 +45,7 @@ rsync -a thirdparty/tcc/ thirdparty/tcc.original/ pushd . -git clone git://repo.or.cz/tinycc.git +git clone https://repo.or.cz/tinycc.git cd tinycc -- 2.39.5