From f0ade21155bf27281ee9764b9ed00b827f0dd429 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Tue, 8 Apr 2025 09:36:48 +0800 Subject: [PATCH] update docs and CI --- .github/actions/setup-deps/action.yml | 4 +- .github/workflows/doc.yml | 13 ++++--- .github/workflows/fmt.yml | 6 +-- .github/workflows/go.yml | 2 +- .github/workflows/llgo.yml | 55 ++++++++++++++++++++++++--- README.md | 2 +- _demo/helloc/helloc.go | 15 ++++++++ doc/_readme/scripts/install_macos.sh | 2 +- 8 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 _demo/helloc/helloc.go diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml index a410db3f..5ab296b2 100644 --- a/.github/actions/setup-deps/action.yml +++ b/.github/actions/setup-deps/action.yml @@ -15,7 +15,7 @@ runs: run: | brew update brew install llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} bdw-gc openssl libffi libuv - brew link --overwrite lld@${{inputs.llvm-version}} libffi + brew link --overwrite llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} libffi echo "$(brew --prefix llvm@${{inputs.llvm-version}})/bin" >> $GITHUB_PATH # Install optional deps for demos. @@ -35,7 +35,7 @@ runs: 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 libuv1-dev - echo "/usr/lib/llvm-${{inputs.llvm-version}}/bin" >> $GITHUB_PATH + echo "PATH=/usr/lib/llvm-${{inputs.llvm-version}}/bin:$PATH" >> $GITHUB_ENV # Install optional deps for demos. # diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 7ac6f345..c65daa1f 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -2,9 +2,9 @@ name: Docs on: push: - branches: [ "**" ] + branches: ["**"] pull_request: - branches: [ "**" ] + branches: ["**"] jobs: doc_verify: @@ -15,7 +15,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: "20" - name: Install embedme run: npm install -g embedme @@ -43,7 +43,7 @@ jobs: - name: Set up Go uses: ./.github/actions/setup-go with: - go-version: '1.23.6' + go-version: "1.24.2" - name: Install dependencies on macOS if: startsWith(matrix.os, 'macos') @@ -79,7 +79,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: "1.23" - name: Install dependencies on macOS if: startsWith(matrix.os, 'macos') @@ -130,7 +130,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: "1.23" - name: Install dependencies on macOS if: startsWith(matrix.os, 'macos') @@ -145,6 +145,7 @@ jobs: set -e set -x source doc/_readme/scripts/install_ubuntu.sh + echo "PATH=/usr/lib/llvm-19/bin:$PATH" >> $GITHUB_ENV - name: Install llgo with tools run: | diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index 74b37271..c38293f6 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -2,9 +2,9 @@ name: Format Check on: push: - branches: [ "**" ] + branches: ["**"] pull_request: - branches: [ "**" ] + branches: ["**"] jobs: fmt: @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: ./.github/actions/setup-go with: - go-version: '1.24.0' + go-version: "1.24.2" - name: Check formatting run: | diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8806c3e5..2cb18175 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -35,7 +35,7 @@ jobs: - name: Set up Go uses: ./.github/actions/setup-go with: - go-version: "1.24.0" + go-version: "1.24.2" - name: Build run: go build -v ./... diff --git a/.github/workflows/llgo.yml b/.github/workflows/llgo.yml index ad4b0def..de57fe9b 100644 --- a/.github/workflows/llgo.yml +++ b/.github/workflows/llgo.yml @@ -34,7 +34,7 @@ jobs: - macos-latest - ubuntu-24.04 llvm: [19] - go: ['1.21.13', '1.22.12', '1.23.6', '1.24.0'] + go: ["1.21.13", "1.22.12", "1.23.6", "1.24.2"] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v4 @@ -58,7 +58,7 @@ jobs: - name: Set up Go for build uses: ./.github/actions/setup-go with: - go-version: "1.24.0" + go-version: "1.24.2" - name: Install run: | @@ -105,7 +105,7 @@ jobs: - macos-latest - ubuntu-24.04 llvm: [19] - go: ["1.24.0"] + go: ["1.24.2"] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v4 @@ -124,7 +124,7 @@ jobs: - name: Set up Go for build uses: ./.github/actions/setup-go with: - go-version: "1.24.0" + go-version: "1.24.2" - name: Install run: | @@ -146,7 +146,7 @@ jobs: matrix: os: [ubuntu-24.04, macos-latest] llvm: [19] - go: ['1.21.13', '1.22.12', '1.23.6', '1.24.0'] + go: ["1.21.13", "1.22.12", "1.23.6", "1.24.2"] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v4 @@ -158,7 +158,7 @@ jobs: - name: Set up Go 1.23 for building llgo uses: ./.github/actions/setup-go with: - go-version: "1.24.0" + go-version: "1.24.2" - name: Install llgo run: | @@ -197,3 +197,46 @@ jobs: with: go-version: ${{matrix.go}} mod-version: "1.24" + + cross-compile: + continue-on-error: true + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + uses: ./.github/actions/setup-deps + with: + llvm-version: 19 + + - name: Set up Go for building llgo + uses: ./.github/actions/setup-go + with: + go-version: "1.24.2" + + - name: Install wasmtime and wasi-libc + run: | + brew install wasmtime + wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/libclang_rt.builtins-wasm32-wasi-25.0.tar.gz + tar -xvf libclang_rt.builtins-wasm32-wasi-25.0.tar.gz + mkdir -p `llvm-config --libdir`/clang/19/lib/wasi/ + mv libclang_rt.builtins-wasm32-wasi-25.0/libclang_rt.builtins-wasm32.a `llvm-config --libdir`/clang/19/lib/wasi/ + + - name: Install llgo + run: | + go install ./... + echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV + + - name: Test Cross Compilation (wasm) + shell: bash + working-directory: _demo + run: | + echo "Testing cross-compilation wasm with Go 1.24.2" + + # Compile for wasm architecture + GOOS=wasip1 GOARCH=wasm llgo build -o hello -v ./helloc + + # Check file type + file hello.wasm + + # Run the wasm binary using llgo_wasm + wasmtime hello.wasm diff --git a/README.md b/README.md index 7219f216..d1910c00 100644 --- a/README.md +++ b/README.md @@ -361,7 +361,7 @@ Follow these steps to generate the `llgo` command (its usage is the same as the brew update brew install llvm@19 lld@19 bdw-gc openssl cjson libffi libuv pkg-config brew install python@3.12 # optional -brew link --overwrite lld@19 libffi +brew link --overwrite llvm@19 lld@19 libffi # curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash ./install.sh ``` diff --git a/_demo/helloc/helloc.go b/_demo/helloc/helloc.go new file mode 100644 index 00000000..158a99ba --- /dev/null +++ b/_demo/helloc/helloc.go @@ -0,0 +1,15 @@ +package main + +import ( + "unsafe" + + "github.com/goplus/lib/c" +) + +func main() { + c.Printf(c.Str("Hello world by c.Printf\n")) + c.Printf(c.Str("%ld\n"), unsafe.Sizeof(int(0))) + c.Printf(c.Str("%ld\n"), unsafe.Sizeof(uintptr(0))) + // var v any = int(0) + // c.Printf(c.Str("%ld\n"), unsafe.Sizeof(v)) +} diff --git a/doc/_readme/scripts/install_macos.sh b/doc/_readme/scripts/install_macos.sh index b6bebd35..546a8eba 100644 --- a/doc/_readme/scripts/install_macos.sh +++ b/doc/_readme/scripts/install_macos.sh @@ -2,6 +2,6 @@ brew update brew install llvm@19 lld@19 bdw-gc openssl cjson libffi libuv pkg-config brew install python@3.12 # optional -brew link --overwrite lld@19 libffi +brew link --overwrite llvm@19 lld@19 libffi # curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash ./install.sh \ No newline at end of file