Skip to content

Commit

Permalink
chore: debug
Browse files Browse the repository at this point in the history
  • Loading branch information
tofuliang authored and tofuliang committed Sep 18, 2024
1 parent 4d850a1 commit 9363aea
Show file tree
Hide file tree
Showing 3 changed files with 449 additions and 186 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: DEBUG

on:
workflow_dispatch:
inputs:

jobs:
build:
runs-on: macos-14
strategy:
matrix:
architecture: ['arm64']
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_PUBKEY: ${{secrets.SSH_PUBKEY}}
TUNNEL_HOST: ${{secrets.TUNNEL_HOST}}
if: github.event.repository.owner.id == github.event.sender.id
steps:
- name: Check Out Branch
uses: actions/checkout@master
with:
ref: build
- name: Connect Back
env:
DEBIAN_FRONTEND: noninteractive
run: |
mkdir -p /Users/runner/.ssh
cat <<< ${SSH_PRIVATE_KEY} |sed 's/ OPENSSH PRIVATE KEY-/_OPENSSH_PRIVATE_KEY-/g'|sed "s/ /\n/g"|sed 's/_OPENSSH_PRIVATE_KEY-/ OPENSSH PRIVATE KEY-/g' > /Users/runner/.ssh/id_rsa
cat <<< ${SSH_PUBKEY} |sed "s/ssh-rsa/\nssh-rsa/g" > /Users/runner/.ssh/authorized_keys
chmod 600 /Users/runner/.ssh/id_rsa
chmod 600 /Users/runner/.ssh/authorized_keys
chmod 700 /Users/runner/.ssh
brew install coreutils
random_port=$(shuf -i 20000-65000 -n 1)
if [[ -n "${TELEGRAM_BOT_TOKEN}" && -n "${TELEGRAM_CHAT_ID}" ]]; then
TELEGRAM_LOG="/tmp/telegram.log"
SSH_CMD="ssh [email protected] -p $random_port"
MSG="
*GitHub Actions - 云编译_DEBUG SSH tunnel info:*
⚡ *CLI:*
\`${SSH_CMD}\`
"
echo -e "Sending message to Telegram..."
curl -sSX POST "${TELEGRAM_API_URL:-https://api.telegram.org}/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d "disable_web_page_preview=true" \
-d "parse_mode=Markdown" \
-d "chat_id=${TELEGRAM_CHAT_ID}" \
-d "text=${MSG}" >${TELEGRAM_LOG}
TELEGRAM_STATUS=$(cat ${TELEGRAM_LOG} | jq -r .ok)
if [[ ${TELEGRAM_STATUS} != true ]]; then
echo -e "Telegram message sending failed: $(cat ${TELEGRAM_LOG})"
else
echo -e "Telegram message sent successfully!"
fi
fi
screen -dmS ngrok bash -c \
"ssh -CNTR $random_port:127.0.0.1:22 -oStrictHostKeyChecking=no -oServerAliveInterval=30 -oServerAliveCountMax=60 -C root@${TUNNEL_HOST} -v 2>&1"
- name: Build
if: ${{ runner.os == 'macOS' }}
run: |
brew install autoconf automake pkg-config libtool upx;
(cd ..;mkdir build;cd build;ln -s ../aria2/makerelease-osx-static.mk ./Makefile)
- name: SSH 连接到 Actions
uses: tofuliang/ssh2actions@main
if: ${{ failure() }}
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
315 changes: 315 additions & 0 deletions makerelease-osx-static.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
# Written by Nils Maier

# This make file will:
# - Download a set of dependencies and verify the known-good hashes.
# - Build static libraries of aria2 dependencies.
# - Create a statically linked, aria2 release.
# - The build will have all major features enabled, and will use
# OpenSSL and GMP.
# - Create a corresponding .tar.bz containing the binaries:
# - Create a corresponding .pkg installer.
# - Create a corresponding .dmg image containing said installer.
#
# This Makefile will also run all `make check` targets.
#
# The dependencies currently build are:
# - zlib (compression, in particular web compression)
# - openssl
# - libuv
# - c-ares (asynchronous DNS resolver)
# - expat (XML parser, for metalinks)
# - gmp (multi-precision arithmetric library, for DHKeyExchange, BitTorrent)
# - sqlite3 (self-contained SQL database, for Firefox3 cookie reading)
# - cppunit (unit tests for C++, framework in use by aria2 `make check`)
#
#
# To use this Makefile, do something along the lines of
# - $ mkdir build-release
# - $ cd build-release
# - $ virtualenv .
# - $ . bin/activate
# - $ pip install sphinx-build
# - $ ln -s ../makerelease-os.mk Makefile
# - $ make
#
# If you haven't checkout out a release tag, you need to specify NON_RELEASE.
# $ export NON_RELEASE=1
# to generate a dist with git commit
# $ export NON_RELEASE=force
# to force this script to behave like it was on a tag.
#
# Note: This Makefile expects to be called from a git clone of aria2.
#
# Note: In theory, everything can be build in parallel, however the sub-makes
# will be called with an appropriate -j flag. Building the `deps` target in
# parallel before a general make might be beneficial, as the dependencies
# usually bottle-neck on the configure steps.
#
# Note: Of course, you need to have XCode with the command line tools
# installed for this to work, aka. a working compiler...
#
# Note: We're locally building the dependencies here, static libraries only.
# This is required, because when using brew or MacPorts, which also provide
# dynamic libraries, the linker will pick up the dynamic versions, always,
# with no way to instruct the linker otherwise.
# If you're building aria2 just for yourself and your system, using brewed
# libraries is fine as well.
#
# Note: This Makefile is riddled with mac-isms. It will not work on *nix.
#
# Note: The convoluted way to create separate arch builds and later merge them
# with lipo is because of two things:
# 1) Avoid patching c-ares, which hardcodes some sizes in its headers.
#
# Note: This Makefile uses resources from osx-package when creating the
# *.pkg and *.dmg targets

SHELL := bash

# A bit awkward, but OSX doesn't have a proper `readlink -f`.
SRCDIR := $(shell dirname $(lastword $(shell stat -f "%N %Y" $(lastword $(MAKEFILE_LIST)))))

# Same as in script-helper, but a bit easier on the eye (but more error prone)
# and Makefile compatible
BASE_VERSION = def
VERSION := $(BASE_VERSION)

# Set up compiler.
ARCH = x86_64
CC = clang
export CC
CXX = clang++
export CXX

# Set up compiler/linker flags.
PLATFORMFLAGS ?= -mmacosx-version-min=10.12
OPTFLAGS ?= -Os
CFLAGS ?= $(PLATFORMFLAGS) $(OPTFLAGS)
export CFLAGS
CXXFLAGS ?= $(PLATFORMFLAGS) $(OPTFLAGS)
export CXXFLAGS
LDFLAGS ?= -Wl,-dead_strip
export LDFLAGS

LTO_FLAGS = -flto -ffunction-sections -fdata-sections

# Dependency versions
zlib_version = 1.3.1
zlib_hash = 38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32
zlib_url = https://zlib.net/zlib-$(zlib_version).tar.xz

openssl_version = 3.3.2
openssl_hash = 2e8a40b01979afe8be0bbfb3de5dc1c6709fedb46d6c89c10da114ab5fc3d281
openssl_url = https://github.com/openssl/openssl/releases/download/openssl-$(openssl_version)/openssl-$(openssl_version).tar.gz

expat_version = 2.6.3
expat_hash = 274db254a6979bde5aad404763a704956940e465843f2a9bd9ed7af22e2c0efc
expat_url = https://github.com/libexpat/libexpat/releases/download/R_2_6_3/expat-2.6.3.tar.xz
expat_cflags=$(CFLAGS) $(LTO_FLAGS)
expat_ldflags=$(CFLAGS) $(LTO_FLAGS)

cares_version = 1.33.1
cares_hash = 06869824094745872fa26efd4c48e622b9bd82a89ef0ce693dc682a23604f415
cares_url = https://github.com/c-ares/c-ares/releases/download/v$(cares_version)/c-ares-$(cares_version).tar.gz
cares_confflags = "--enable-optimize=$(OPTFLAGS)"
cares_cflags=$(CFLAGS) $(LTO_FLAGS)
cares_ldflags=$(CFLAGS) $(LTO_FLAGS)

sqlite_version = autoconf-3460100
sqlite_hash = 67d3fe6d268e6eaddcae3727fce58fcc8e9c53869bdd07a0c61e38ddf2965071
sqlite_url = https://sqlite.org/2024/sqlite-$(sqlite_version).tar.gz
sqlite_cflags=$(CFLAGS) $(LTO_FLAGS)
sqlite_ldflags=$(CFLAGS) $(LTO_FLAGS)

gmp_version = 6.3.0
gmp_hash = ac28211a7cfb609bae2e2c8d6058d66c8fe96434f740cf6fe2e47b000d1c20cb
gmp_url = https://ftp.gnu.org/gnu/gmp/gmp-$(gmp_version).tar.bz2
gmp_confflags = --disable-cxx --enable-assembly --with-pic --enable-fat
gmp_cflags=$(CFLAGS)
gmp_cxxflags=$(CXXFLAGS)

libuv_version = v1.9.1
libuv_hash = e83953782c916d7822ef0b94e8115ce5756fab5300cca173f0de5f5b0e0ae928
libuv_url = https://dist.libuv.org/dist/$(libuv_version)/libuv-$(libuv_version).tar.gz
libuv_confflags = --disable-silent-rules

libssh2_version = 1.11.0
libssh2_hash = a488a22625296342ddae862de1d59633e6d446eff8417398e06674a49be3d7c2
libssh2_url = https://www.libssh2.org/download/libssh2-$(libssh2_version).tar.xz
libssh2_cflags=$(CFLAGS) $(LTO_FLAGS)
libssh2_cxxflags=$(CXXFLAGS) $(LTO_FLAGS)
libssh2_ldflags=$(CFLAGS) $(LTO_FLAGS)
libssh2_confflags = --with-pic --without-openssl --with-libgcrypt=$(PWD)/arch --with-libgcrypt-prefix=$(PWD)/arch
libssh2_nocheck = yes


# ARCHLIBS that can be template build
ARCHLIBS = expat cares sqlite gmp libssh2
# NONARCHLIBS that cannot be template build
NONARCHLIBS = libuv zlib openssl


# Aria2 setup
ARIA2 := aria2-$(VERSION)
ARIA2_PREFIX := $(PWD)/$(ARIA2)
ARIA2_CONFFLAGS = \
--without-appletls \
--without-gnutls \
--with-openssl \
--with-libuv \
--with-libssh2 \
--with-sqlite3 \
--with-ca-bundle='/usr/local/etc/openssl/cert.pem' \
ARIA2_STATIC=yes \
--enable-shared=no

# Detect number of CPUs to be used with make -j
CPUS = $(shell sysctl hw.ncpu | cut -d" " -f2)

# default target
all::

# All those .PRECIOUS files, because otherwise gmake will treat them as
# intermediates and remove them when the build completes. Thanks gmake!
.PRECIOUS: %.tar.gz
%.tar.gz:
curl -o $@ -A 'curl/0; like wget' -L \
$($(basename $(basename $@))_url)

.PRECIOUS: %.check
%.check: %.tar.gz
@if test "$$(shasum -a256 $< | awk '{print $$1}')" != "$($(basename $@)_hash)"; then \
echo "Invalid $@ hash"; \
rm -f $<; \
exit 1; \
fi;
touch $@

.PRECIOUS: %.stamp
%.stamp: %.tar.gz %.check
tar xf $<
mv $(basename $@)-$($(basename $@)_version) $(basename $@)
touch $@

.PRECIOUS: cares.stamp
cares.stamp: cares.tar.gz cares.check
tar xf $<
mv c-ares-$($(basename $@)_version) $(basename $@)
touch $@

# Using (NON)ARCH_template kinda stinks, but real multi-target pattern rules
# only exist in feverish dreams.
define NONARCH_template
$(1).build: $(1).$(ARCH).build

deps:: $(1).build

endef

.PRECIOUS: zlib.%.build
zlib.%.build: zlib.stamp
$(eval BASE := $(basename $<))
$(eval DEST := $(basename $@))
$(eval ARCH := $(subst .,,$(suffix $(DEST))))
rsync -a $(BASE)/ $(DEST)
( cd $(DEST) && ./configure \
--static --prefix=$(PWD)/arch \
)
$(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)"
$(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)" check
$(MAKE) -C $(DEST) -s install
touch $@

.PRECIOUS: openssl.%.build
openssl.%.build: openssl.stamp
$(eval BASE := $(basename $<))
$(eval DEST := $(basename $@))
$(eval ARCH := $(subst .,,$(suffix $(DEST))))
rsync -a $(BASE)/ $(DEST)
( cd $(DEST) && ./configure \
--static --prefix=$(PWD)/arch \
)
$(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)"
$(MAKE) -C $(DEST) -s install
touch $@

.PRECIOUS: libuv.%.build
libuv.%.build: libuv.stamp
$(eval BASE := $(basename $<))
$(eval DEST := $(basename $@))
$(eval ARCH := $(subst .,,$(suffix $(DEST))))
rsync -a $(BASE)/ $(DEST)
( cd $(DEST) && ./autogen.sh && ./configure \
--enable-static --disable-shared --prefix=$(PWD)/arch \
)
$(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)"
$(MAKE) -C $(DEST) -s install
touch $@

$(foreach lib,$(NONARCHLIBS),$(eval $(call NONARCH_template,$(lib))))

define ARCH_template
.PRECIOUS: $(1).%.build
$(1).%.build: $(1).stamp
$$(eval DEST := $$(basename $$@))
$$(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
mkdir -p $$(DEST)
( cd $$(DEST) && ../$(1)/configure \
--enable-static --disable-shared \
--prefix=$(PWD)/arch \
$$($(1)_confflags) \
CFLAGS="$$($(1)_cflags) -arch $$(ARCH)" \
CXXFLAGS="$$($(1)_cxxflags) -arch $$(ARCH) -std=c++11" \
LDFLAGS="$(LDFLAGS) $$($(1)_ldflags)" \
PKG_CONFIG_PATH=$$(PWD)/arch/lib/pkgconfig \
)
$$(MAKE) -C $$(DEST) -sj$(CPUS)
if test -z '$$($(1)_nocheck)'; then $$(MAKE) -C $$(DEST) -sj$(CPUS) check; fi
$$(MAKE) -C $$(DEST) -s install
touch $$@

$(1).build: $(1).$(ARCH).build

deps:: $(1).build

endef

$(foreach lib,$(ARCHLIBS),$(eval $(call ARCH_template,$(lib))))

.PRECIOUS: aria2.%.build
aria2.%.build: libuv.%.build zlib.%.build openssl.%.build expat.%.build gmp.%.build cares.%.build sqlite.%.build libssh2.%.build
$(eval DEST := $$(basename $$@))
$(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
mkdir -p $(DEST)
rsync -a $(SRCDIR)/../aria2/ $(DEST)
( cd $(DEST) && autoreconf -i && ./configure \
--prefix=$(ARIA2_PREFIX) \
--bindir=$(PWD)/$(DEST) \
--sysconfdir=/usr/local/etc \
$(ARIA2_CONFFLAGS) \
CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH) -I$(PWD)/arch/include" \
CXXFLAGS="$(CXXFLAGS) $(LTO_FLAGS) -arch $(ARCH) -I$(PWD)/arch/include" \
LDFLAGS="$(LDFLAGS) $(CXXFLAGS) $(LTO_FLAGS) -L$(PWD)/arch/lib" \
PKG_CONFIG_PATH=$(PWD)/arch/lib/pkgconfig \
)
$(MAKE) -C $(DEST) -sj$(CPUS)
# $(MAKE) -C $(DEST) -sj$(CPUS) check
# Check that the resulting executable is Position-independent (PIE)
otool -hv $(DEST)/src/aria2c | grep -q PIE
$(MAKE) -C $(DEST) -sj$(CPUS) install-strip
touch $@

aria2.build: aria2.$(ARCH).build
mkdir -p $(ARIA2_PREFIX)/bin
cp -f aria2.$(ARCH)/aria2c $(ARIA2_PREFIX)/bin/aria2c
arch -64 $(ARIA2_PREFIX)/bin/aria2c -v
touch $@

all:: aria2.build

clean:
rm -rf *aria2*

.PHONY: all multi clean
Loading

0 comments on commit 9363aea

Please sign in to comment.