From a64b32bf9ce2b90baf32c8640a2a0df9188680a9 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Wed, 8 Jan 2025 15:36:21 +0800 Subject: [PATCH] ci: compile go with go1.23, test llgo with go 1.20-1.23 --- .github/actions/setup-deps/action.yml | 48 ++++++++++++++ .github/workflows/fmt.yml | 30 +++++++++ .github/workflows/go.yml | 96 ++------------------------- .github/workflows/llgo.yml | 95 ++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 90 deletions(-) create mode 100644 .github/actions/setup-deps/action.yml create mode 100644 .github/workflows/fmt.yml create mode 100644 .github/workflows/llgo.yml diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml new file mode 100644 index 00000000..5781f7ee --- /dev/null +++ b/.github/actions/setup-deps/action.yml @@ -0,0 +1,48 @@ +name: "Setup LLGO Dependencies" +description: "Install all required dependencies for LLGO" +inputs: + llvm-version: + description: "LLVM version to install" + required: true + default: "18" + +runs: + using: "composite" + steps: + - name: Install macOS dependencies + if: runner.os == 'macOS' + shell: bash + run: | + brew update + brew install llvm@${{inputs.llvm-version}} bdw-gc openssl libffi + brew link --force libffi + echo "$(brew --prefix llvm@${{inputs.llvm-version}})/bin" >> $GITHUB_PATH + + # Install optional deps for demos. + # + # NOTE: Keep this list updated as new deps are introduced. + opt_deps=( + cjson # for github.com/goplus/llgo/c/cjson + sqlite # for github.com/goplus/llgo/c/sqlite + python@3.12 # for github.com/goplus/llgo/py + ) + brew install "${opt_deps[@]}" + - name: Install Ubuntu dependencies + if: runner.os == 'Linux' + shell: bash + run: | + echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${{inputs.llvm-version}} main" | sudo tee /etc/apt/sources.list.d/llvm.list + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo apt-get update + sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev + echo "/usr/lib/llvm-${{inputs.llvm-version}}/bin" >> $GITHUB_PATH + + # Install optional deps for demos. + # + # NOTE: Keep this list updated as new deps are introduced. + opt_deps=( + libcjson-dev # for github.com/goplus/llgo/c/cjson + libsqlite3-dev # for github.com/goplus/llgo/c/sqlite + python3.12-dev # for github.com/goplus/llgo/py + ) + sudo apt-get install -y "${opt_deps[@]}" diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml new file mode 100644 index 00000000..243bead5 --- /dev/null +++ b/.github/workflows/fmt.yml @@ -0,0 +1,30 @@ +name: Format Check + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Check formatting + run: | + for dir in . compiler runtime; do + pushd $dir + if [ -n "$(go fmt ./...)" ]; then + echo "Some files are not properly formatted. Please run 'go fmt ./...'" + exit 1 + fi + popd + done + echo "All files are properly formatted." diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index db78e19b..9c0f1c5e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -10,23 +10,6 @@ on: branches: [ "**" ] jobs: - fmt: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.23' - - - name: Check formatting - run: | - if [ -n "$(go fmt ./...)" ]; then - echo "Some files are not properly formatted. Please run 'go fmt ./...'" - exit 1 - fi - test: strategy: matrix: @@ -35,46 +18,15 @@ jobs: - ubuntu-24.04 llvm: [18] runs-on: ${{matrix.os}} + defaults: + run: + working-directory: compiler steps: - uses: actions/checkout@v4 - - name: Install dependencies - if: startsWith(matrix.os, 'macos') - run: | - brew update - brew install llvm@${{matrix.llvm}} bdw-gc openssl libffi - brew link --force libffi - echo "$(brew --prefix llvm@${{matrix.llvm}})/bin" >> $GITHUB_PATH - - # Install optional deps for demos. - # - # NOTE: Keep this list updated as new deps are introduced. - opt_deps=( - cjson # for github.com/goplus/llgo/c/cjson - sqlite # for github.com/goplus/llgo/c/sqlite - python@3.12 # for github.com/goplus/llgo/py - ) - brew install "${opt_deps[@]}" - - - name: Install dependencies - if: startsWith(matrix.os, 'ubuntu') - run: | - echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${{matrix.llvm}} main" | sudo tee /etc/apt/sources.list.d/llvm.list - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo apt-get update - sudo apt-get install -y llvm-${{matrix.llvm}}-dev clang-${{matrix.llvm}} libclang-${{matrix.llvm}}-dev lld-${{matrix.llvm}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev - echo "/usr/lib/llvm-${{matrix.llvm}}/bin" >> $GITHUB_PATH - - # Install optional deps for demos. - # - # NOTE: Keep this list updated as new deps are introduced. - opt_deps=( - libcjson-dev # for github.com/goplus/llgo/c/cjson - libsqlite3-dev # for github.com/goplus/llgo/c/sqlite - python3.12-dev # for github.com/goplus/llgo/py - ) - sudo apt-get install -y "${opt_deps[@]}" - + uses: ./.github/actions/setup-deps + with: + llvm-version: ${{matrix.llvm}} - name: Install further optional dependencies for demos run: | wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin @@ -98,9 +50,6 @@ jobs: - name: Build run: go build -v ./... - - name: Install - run: go install ./... - - name: Test if: ${{!startsWith(matrix.os, 'macos')}} run: go test -v ./... @@ -109,39 +58,6 @@ jobs: if: startsWith(matrix.os, 'macos') run: go test -v -coverprofile="coverage.txt" -covermode=atomic ./... - - name: LLGO tests - if: ${{!startsWith(matrix.os, 'ubuntu')}} - run: | - echo "Test result on ${{matrix.os}} with LLVM ${{matrix.llvm}}" > result.md - bash .github/workflows/test_llgo.sh - - - name: chore/_xtool build tests - run: | - cd chore/_xtool - llgo build -v ./... - - - name: LLDB tests - if: ${{startsWith(matrix.os, 'macos')}} - run: | - echo "Test lldb with llgo plugin on ${{matrix.os}} with LLVM ${{matrix.llvm}}" - bash _lldb/runtest.sh -v - - - name: Test demos - run: | - # TODO(lijie): force python3-embed to be linked with python-3.12-embed - # Currently, python3-embed is python-3.13-embed, doesn't work with pytorch - # Will remove this after pytorch is fixed. - pcdir=$HOME/pc - mkdir -p $pcdir - libdir=$(pkg-config --variable=libdir python-3.12-embed) - echo "libdir: $libdir" - ln -s $libdir/pkgconfig/python-3.12-embed.pc $pcdir/python3-embed.pc - export PKG_CONFIG_PATH=$pcdir - bash .github/workflows/test_demo.sh - - - name: Show test result - run: cat result.md - - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 with: diff --git a/.github/workflows/llgo.yml b/.github/workflows/llgo.yml new file mode 100644 index 00000000..48ccc226 --- /dev/null +++ b/.github/workflows/llgo.yml @@ -0,0 +1,95 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + +jobs: + test: + strategy: + matrix: + os: + - macos-latest + - ubuntu-24.04 + llvm: [18] + go: ['1.20', '1.21', '1.22', '1.23'] + runs-on: ${{matrix.os}} + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + uses: ./.github/actions/setup-deps + with: + llvm-version: ${{matrix.llvm}} + - name: Install further optional dependencies for demos + run: | + wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin + py_deps=( + numpy # for github.com/goplus/llgo/py/numpy + torch # for github.com/goplus/llgo/py/torch + ) + pip3.12 install --break-system-packages "${py_deps[@]}" + + - name: Set up Go for build + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Install + working-directory: compiler + run: | + go install ./... + echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV + + - name: Set up Go for testing + uses: actions/setup-go@v5 + with: + go-version: ${{matrix.go}} + + - name: Verify Go version + run: | + go_version=$(go version | cut -d' ' -f3 | sed 's/go//') + if [[ "$go_version" != "${{matrix.go}}"* ]]; then + echo "Expected Go version ${{matrix.go}}, but got $go_version" + exit 1 + fi + echo "Using Go version: $go_version" + + - name: chore/_xtool build tests + working-directory: compiler + run: | + cd chore/_xtool + llgo build -v ./... + + - name: LLDB tests + if: ${{startsWith(matrix.os, 'macos')}} + working-directory: compiler + run: | + echo "Test lldb with llgo plugin on ${{matrix.os}} with LLVM ${{matrix.llvm}}" + bash _lldb/runtest.sh -v + + - name: LLGO tests + if: ${{!startsWith(matrix.os, 'ubuntu')}} + run: | + echo "Test result on ${{matrix.os}} with LLVM ${{matrix.llvm}}" > result.md + bash ./.github/workflows/test_llgo.sh + + - name: Test demos + run: | + # TODO(lijie): force python3-embed to be linked with python-3.12-embed + # Currently, python3-embed is python-3.13-embed, doesn't work with pytorch + # Will remove this after pytorch is fixed. + pcdir=$HOME/pc + mkdir -p $pcdir + libdir=$(pkg-config --variable=libdir python-3.12-embed) + echo "libdir: $libdir" + ln -s $libdir/pkgconfig/python-3.12-embed.pc $pcdir/python3-embed.pc + export PKG_CONFIG_PATH=$pcdir + bash .github/workflows/test_demo.sh + + - name: Show test result + run: cat result.md