diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1051d5377..40abc7e62 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,16 +16,13 @@ env: defaults: run: shell: bash - working-directory: pipy jobs: set-release-version: name: set-release-version runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - path: pipy + - uses: actions/checkout@v4 - name: Set RELEASE_VERSION id: version @@ -57,17 +54,11 @@ jobs: name: x86-binary runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - with: - path: pipy + - uses: actions/checkout@v4 - name: Show envs run: export - - uses: actions/setup-node@v3 - with: - node-version: 16 - - name: Build id: build env: @@ -101,6 +92,12 @@ jobs: s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}/$(uname -m)/binary/${{steps.build.outputs.artifact_name}} fi + - name: Upload artifact to workflow + uses: actions/upload-artifact@v4 + with: + name: ${{steps.build.outputs.artifact_name}} + path: ${{steps.build.outputs.artifact_name}} + outputs: artifact_name: ${{steps.build.outputs.artifact_name}} arch: ${{steps.build.outputs.arch}} @@ -110,12 +107,10 @@ jobs: name: x86-alpine-docker runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - path: pipy + - uses: actions/checkout@v4 - name: Setup buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Show envs run: export @@ -162,17 +157,11 @@ jobs: name: aarch64-binary runs-on: [self-hosted, arm64] steps: - - uses: actions/checkout@v3 - with: - path: pipy + - uses: actions/checkout@v4 - name: Show envs run: export - - uses: actions/setup-node@v3 - with: - node-version: 16 - - name: Build id: build env: @@ -205,6 +194,12 @@ jobs: s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}/$(uname -m)/binary/${{steps.build.outputs.artifact_name}} fi + - name: Upload artifact to workflow + uses: actions/upload-artifact@v4 + with: + name: ${{steps.build.outputs.artifact_name}} + path: ${{steps.build.outputs.artifact_name}} + outputs: artifact_name: ${{steps.build.outputs.artifact_name}} arch: ${{steps.build.outputs.arch}} @@ -214,12 +209,10 @@ jobs: name: aarch64-alpine-docker runs-on: [self-hosted, arm64] steps: - - uses: actions/checkout@v3 - with: - path: pipy + - uses: actions/checkout@v4 - name: Setup buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Show envs run: export @@ -266,9 +259,7 @@ jobs: name: x86-rpm runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - path: pipy + - uses: actions/checkout@v4 - name: Show envs run: export @@ -306,10 +297,232 @@ jobs: s3cmd put rpm/${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}/$(uname -m)/rpm/${TARGET_FILE_NAME} fi + - name: Upload artifact to workflow + uses: actions/upload-artifact@v4 + with: + name: ${{steps.build.outputs.artifact_name}} + path: rpm/${{steps.build.outputs.artifact_name}} + + outputs: + artifact_name: ${{steps.build.outputs.artifact_name}} + arch: ${{steps.build.outputs.arch}} + + x86-macos: + needs: set-release-version + name: x86-macos + runs-on: macos-13 + if: ${{ !contains(needs.set-release-version.outputs.release_version, 'nightly') }} + steps: + - uses: actions/checkout@v4 + + - name: Show envs + run: export + + - name: Build + id: build + env: + RELEASE_VERSION: ${{ needs.set-release-version.outputs.release_version }} + run: | + set -x + export CC=$(brew --prefix llvm@15)/bin/clang + export CXX=$(brew --prefix llvm@15)/bin/clang++ + ./build.sh -p -t ${RELEASE_VERSION} + ls -l + echo "artifact_name=$(ls *${RELEASE_VERSION}*.tar.gz)" >> $GITHUB_OUTPUT + echo "arch=$(uname -m)" >> $GITHUB_OUTPUT + + - name: Setup s3cmd + run: | + brew install s3cmd + cat > $HOME/.s3cfg << EOF + bucket_location = ${{ secrets.S3_REGION }} + host_base = ${{ secrets.S3_GLOBAL_ACC_HOST_BASE }} + host_bucket = %(bucket)s.${{ secrets.S3_GLOBAL_ACC_HOST_BASE}} + access_key = ${{ secrets.S3_ACCESS_KEY }} + secret_key = ${{ secrets.S3_SECRET_KEY }} + EOF + + - name: Upload artifacts + env: + RELEASE_VERSION: ${{ needs.set-release-version.outputs.release_version }} + run: | + if [[ "$RELEASE_VERSION" == "nightly"* ]] + then + s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}-nightly/$(uname -m)/binary/${{steps.build.outputs.artifact_name}} + else + s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}/$(uname -m)/binary/${{steps.build.outputs.artifact_name}} + fi + + - name: Upload artifact to workflow + uses: actions/upload-artifact@v4 + with: + name: ${{steps.build.outputs.artifact_name}} + path: ${{steps.build.outputs.artifact_name}} + + outputs: + artifact_name: ${{steps.build.outputs.artifact_name}} + arch: ${{steps.build.outputs.arch}} + + aarch64-macos: + needs: set-release-version + name: aarch64-macos + runs-on: macos-latest + if: ${{ !contains(needs.set-release-version.outputs.release_version, 'nightly') }} + steps: + - uses: actions/checkout@v4 + + - name: Show envs + run: export + + - name: Build + id: build + env: + RELEASE_VERSION: ${{ needs.set-release-version.outputs.release_version }} + run: | + set -x + export CC=$(brew --prefix llvm@15)/bin/clang + export CXX=$(brew --prefix llvm@15)/bin/clang++ + ./build.sh -p -t ${RELEASE_VERSION} + ls -l + echo "artifact_name=$(ls *${RELEASE_VERSION}*.tar.gz)" >> $GITHUB_OUTPUT + echo "arch=$(uname -m)" >> $GITHUB_OUTPUT + + - name: Setup s3cmd + run: | + brew install s3cmd + cat > $HOME/.s3cfg << EOF + bucket_location = ${{ secrets.S3_REGION }} + host_base = ${{ secrets.S3_GLOBAL_ACC_HOST_BASE }} + host_bucket = %(bucket)s.${{ secrets.S3_GLOBAL_ACC_HOST_BASE}} + access_key = ${{ secrets.S3_ACCESS_KEY }} + secret_key = ${{ secrets.S3_SECRET_KEY }} + EOF + + - name: Upload artifacts + env: + RELEASE_VERSION: ${{ needs.set-release-version.outputs.release_version }} + run: | + if [[ "$RELEASE_VERSION" == "nightly"* ]] + then + s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}-nightly/aarch64/binary/${{steps.build.outputs.artifact_name}} + else + s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}/aarch64/binary/${{steps.build.outputs.artifact_name}} + fi + + - name: Upload artifact to workflow + uses: actions/upload-artifact@v4 + with: + name: ${{steps.build.outputs.artifact_name}} + path: ${{steps.build.outputs.artifact_name}} + + outputs: + artifact_name: ${{steps.build.outputs.artifact_name}} + arch: ${{steps.build.outputs.arch}} + + android: + needs: set-release-version + name: android + runs-on: ubuntu-latest + if: ${{ !contains(needs.set-release-version.outputs.release_version, 'nightly') }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - uses: nttld/setup-ndk@v1 + id: setup-ndk + with: + ndk-version: r26c + + - uses: seanmiddleditch/gha-setup-ninja@v4 + id: setup-ninja + with: + version: 1.11.1 + + - name: Show envs + run: export + + - name: Build + id: build + env: + RELEASE_VERSION: ${{ needs.set-release-version.outputs.release_version }} + NDK: "${{ steps.setup-ndk.outputs.ndk-path }}" + run: | + set -x + ./build.sh -nap + ls -al + echo "artifact_name=$(ls *${RELEASE_VERSION}*.tar.gz)" >> $GITHUB_OUTPUT + echo "arch=$(uname -m)" >> $GITHUB_OUTPUT + + - name: Setup s3cmd + run: | + sudo apt-get install -y s3cmd + cat > $HOME/.s3cfg << EOF + bucket_location = ${{ secrets.S3_REGION }} + host_base = ${{ secrets.S3_GLOBAL_ACC_HOST_BASE }} + host_bucket = %(bucket)s.${{ secrets.S3_GLOBAL_ACC_HOST_BASE}} + access_key = ${{ secrets.S3_ACCESS_KEY }} + secret_key = ${{ secrets.S3_SECRET_KEY }} + EOF + + - name: Upload artifacts + env: + RELEASE_VERSION: ${{ needs.set-release-version.outputs.release_version }} + run: | + if [[ "$RELEASE_VERSION" == "nightly"* ]] + then + s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}-nightly/arm64-v8a/binary/${{steps.build.outputs.artifact_name}} + else + s3cmd put ${{steps.build.outputs.artifact_name}} s3://${{ secrets.S3_BUCKET }}/${S3_PATH}/arm64-v8a/binary/${{steps.build.outputs.artifact_name}} + fi + + - name: Upload artifact to workflow + uses: actions/upload-artifact@v4 + with: + name: ${{steps.build.outputs.artifact_name}} + path: ${{steps.build.outputs.artifact_name}} + outputs: artifact_name: ${{steps.build.outputs.artifact_name}} arch: ${{steps.build.outputs.arch}} + create-release: + name: create release + runs-on: ubuntu-latest + if: ${{ !contains(needs.set-release-version.outputs.release_version, 'nightly') }} + needs: + - set-release-version + - x86-binary + - aarch64-binary + - x86-alpine-docker + - aarch64-alpine-docker + - x86-rpm + - x86-macos + - aarch64-macos + - android + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + + - name: Check downloads + run: | + ls -alR + + - name: Create draft release + id: create_release + uses: softprops/action-gh-release@v2 + with: + draft: true + files: | + ${{ needs.x86-binary.outputs.artifact_name }}/${{ needs.x86-binary.outputs.artifact_name }} + ${{ needs.x86-rpm.outputs.artifact_name }}/${{ needs.x86-rpm.outputs.artifact_name }} + ${{ needs.x86-macos.outputs.artifact_name }}/${{ needs.x86-macos.outputs.artifact_name }} + ${{ needs.aarch64-binary.outputs.artifact_name }}/${{ needs.aarch64-binary.outputs.artifact_name }} + ${{ needs.aarch64-macos.outputs.artifact_name }}/${{ needs.aarch64-macos.outputs.artifact_name }} + ${{ needs.android.outputs.artifact_name }}/${{ needs.android.outputs.artifact_name }} + save-log: name: save log runs-on: ubuntu-latest @@ -320,22 +533,30 @@ jobs: - x86-alpine-docker - aarch64-alpine-docker - x86-rpm + - x86-macos + - aarch64-macos + - android + - create-release + if: ${{ always() && !contains(join(needs.*.result, ','), 'failure') && !contains(needs.x86-binary.result, 'skipped')}} steps: - name: Save log - uses: peter-evans/repository-dispatch@v1 + uses: peter-evans/repository-dispatch@v3 with: token: ${{ secrets.REPO_DISPATCH_PAT }} repository: ${{ secrets.REPO_FOR_LOG }} event-type: save-log client-payload: | { - "github": ${{toJSON(github)}}, - "release_version": "${{needs.set-release-version.outputs.release_version}}", - "artifacts": [ - { "type": "rpm", "arch": "${{needs.x86-rpm.outputs.arch}}", "name": "${{ needs.x86-rpm.outputs.artifact_name }}" }, - { "type": "binary", "arch": "${{needs.x86-binary.outputs.arch}}", "name": "${{ needs.x86-binary.outputs.artifact_name }}" }, - { "type": "binary", "arch": "${{needs.aarch64-binary.outputs.arch}}", "name": "${{ needs.aarch64-binary.outputs.artifact_name }}" }, - { "type": "image", "arch": "${{needs.x86-alpine-docker.outputs.arch}}", "name": "${{ needs.x86-alpine-docker.outputs.artifact_name }}" }, - { "type": "image", "arch": "${{needs.aarch64-alpine-docker.outputs.arch}}", "name": "${{ needs.aarch64-alpine-docker.outputs.artifact_name }}" } - ] - } + "github": ${{toJSON(github)}}, + "release_version": "${{needs.set-release-version.outputs.release_version}}", + "artifacts": [ + { "type": "rpm", "arch": "${{needs.x86-rpm.outputs.arch}}", "name": "${{ needs.x86-rpm.outputs.artifact_name }}" }, + { "type": "binary", "arch": "${{needs.x86-binary.outputs.arch}}", "name": "${{ needs.x86-binary.outputs.artifact_name }}" }, + { "type": "binary", "arch": "${{needs.aarch64-binary.outputs.arch}}", "name": "${{ needs.aarch64-binary.outputs.artifact_name }}" }, + { "type": "binary", "arch": "${{needs.x86-macos.outputs.arch}}", "name": "${{ needs.x86-macos.outputs.artifact_name }}" }, + { "type": "binary", "arch": "${{needs.aarch64-macos.outputs.arch}}", "name": "${{ needs.aarch64-macos.outputs.artifact_name }}" }, + { "type": "binary", "arch": "${{needs.android.outputs.arch}}", "name": "${{ needs.android.outputs.artifact_name }}" }, + { "type": "image", "arch": "${{needs.x86-alpine-docker.outputs.arch}}", "name": "${{ needs.x86-alpine-docker.outputs.artifact_name }}" }, + { "type": "image", "arch": "${{needs.aarch64-alpine-docker.outputs.arch}}", "name": "${{ needs.aarch64-alpine-docker.outputs.artifact_name }}" } + ] + } diff --git a/.github/workflows/gui.yml b/.github/workflows/gui.yml index 964ce7d6b..c893fe664 100644 --- a/.github/workflows/gui.yml +++ b/.github/workflows/gui.yml @@ -19,13 +19,13 @@ jobs: name: build-gui runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: path: pipy - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - name: Show node version run: | diff --git a/Dockerfile b/Dockerfile index 11a505877..2352118c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,7 +42,7 @@ RUN rm -fr pipy/build \ && export CI_COMMIT_SHA \ && export CI_COMMIT_TAG=${VERSION}-${REVISION} \ && export CI_COMMIT_DATE \ - && cmake -DPIPY_GUI=${PIPY_GUI} -DPIPY_STATIC=${PIPY_STATIC} -DPIPY_SAMPLES=${PIPY_GUI} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. \ + && cmake -DPIPY_GUI=${PIPY_GUI} -DPIPY_STATIC=${PIPY_STATIC} -DPIPY_CODEBASES=${PIPY_GUI} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. \ && make -j$(getconf _NPROCESSORS_ONLN) \ && mkdir ${pkg_confdir} \ && cp /pipy/bin/pipy ${pkg_bindir} \ diff --git a/build.sh b/build.sh index d29120f1a..82a633528 100755 --- a/build.sh +++ b/build.sh @@ -15,7 +15,7 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then PHYS_DIR=$(pwd -P) RESULT=$PHYS_DIR/$TARGET_FILE PIPY_DIR=$(dirname $RESULT) - OS_NAME=darwin + OS_NAME=macos fi # Number of processors to build. @@ -25,6 +25,7 @@ __NPROC=${NPROC:-$(getconf _NPROCESSORS_ONLN)} BUILD_CONTAINER=false BUILD_RPM=false BUILD_BINARY=true +BUILD_ANDROID=false BUILD_TYPE=Release PACKAGE_OUTPUTS=false @@ -36,16 +37,17 @@ PKG_NAME=${PKG_NAME:-pipy} PIPY_STATIC=OFF PIPY_GUI=${PIPY_GUI:-OFF} -OS_ARCH=$(uname -m) +OS_ARCH=$(uname -m | sed 's#arm64#aarch64#g') ##### End Default environment variables ######### -SHORT_OPTS="crsgt:nhpd" +SHORT_OPTS="crsgt:nhpda" function usage() { echo "Usage: $0 [-h|-c|-r|-s|-g|-n|-t ]" 1>&2 echo " -h Show this help message" echo " -t Specify the release version (should be one of the release tags, e.g. 0.2.0-15)" echo " -c Build a container image" + echo " -a Build a android binary" echo " -r Build a CentOS/RHEL RPM package" echo " -n Build a stand-alone executable (default: yes)" echo " -d Build with debugging information (default: no)" @@ -94,6 +96,10 @@ while true ; do BUILD_TYPE="Debug" shift ;; + -a) + BUILD_ANDROID=true + shift + ;; -h) usage ;; @@ -162,7 +168,11 @@ function __build_deps_check() { elif [ ! -z $(command -v cmake) ]; then export CMAKE=cmake fi - clang --version 2>&1 > /dev/null && clang++ --version 2>&1 > /dev/null && export __CLANG_EXIST=true + + export CC=${CC:-clang} + export CXX=${CXX:-clang++} + + $CC --version 2>&1 > /dev/null && $CXX --version 2>&1 > /dev/null && export __CLANG_EXIST=true if [ "x"$CMAKE = "x" ] || ! $__CLANG_EXIST ; then echo "Command \`cmake\` or \`clang\` not found." && exit -1; fi __NODE_VERSION=`node --version 2> /dev/null` version_compare "v12" "$__NODE_VERSION" @@ -175,10 +185,7 @@ function __build_deps_check() { function build() { __build_deps_check - cd ${PIPY_DIR} - export CC=clang - export CXX=clang++ cd ${PIPY_DIR} if [ $PIPY_GUI == "ON" ] ; then npm install @@ -271,3 +278,62 @@ if $BUILD_CONTAINER; then docker save ${IMAGE}:$IMAGE_TAG | gzip > ${IMAGE##flomesh/}-${IMAGE_TAG}-alpine-${OS_ARCH}.tar.gz fi fi + +if $BUILD_ANDROID; then + cd $PIPY_DIR + + if [ -z "$NDK" ] || [ ! -f "$NDK/build/cmake/android.toolchain.cmake" ] + then + echo "Can't find NDK, exists..." + exit 1 + fi + + export ANDROID_NDK_ROOT=$NDK + + cd $PIPY_DIR/deps/openssl-3.2.0 + + mkdir -p android && cd android + + ANDROID_TARGET_API=34 + ANDROID_TARGET_ABI=arm64-v8a + + OUTPUT=${PWD}/${ANDROID_TARGET_ABI} + + PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH + ../config android-arm64 -D__ANDROID_API__=${ANDROID_TARGET_API} -static no-asm no-shared no-tests --prefix=${OUTPUT} + + make + make install_sw + + cd $PIPY_DIR + rm -rf build && mkdir build + cd $PIPY_DIR/build + + cmake -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-34 -DCMAKE_ANDROID_STL_TYPE=c++_static \ + -DANDROID_ALLOW_UNDEFINED_SYMBOLS=TRUE \ + -DPIPY_OPENSSL=${PIPY_DIR}/deps/openssl-3.2.0/android/arm64-v8a \ + -DPIPY_USE_SYSTEM_ZLIB=ON \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_FLAGS_RELEASE=-g0 \ + -DPIPY_LTO=OFF -DPIPY_GUI=OFF -DPIPY_CODEBASES=OFF \ + -DZLIB_LIBRARY=/usr/lib/x86_64-linux-gnu/libz.a -DZLIB_INCLUDE_DIR=/usr/lib/x86_64-linux-gnu -GNinja .. + + ninja || exit $? + + if $PACKAGE_OUTPUTS; then + cd $PIPY_DIR + + test -d usr/local/lib || mkdir -p usr/local/lib + test -d usr/local/bin || mkdir -p usr/local/bin + + cp $ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so usr/local/lib + cp bin/pipy usr/local/bin/pipy + + tar zcvf \ + ${PKG_NAME}-${RELEASE_VERSION}-android-${ANDROID_TARGET_ABI/-/_}.tar.gz \ + usr/local/lib/libc++_shared.so \ + usr/local/bin/pipy + fi +fi