Skip to content

Commit be0e42c

Browse files
authored
Merge pull request #1057 from cpunion/cross-compiling
Cross compiling
2 parents b11eb74 + 3a883b8 commit be0e42c

39 files changed

Lines changed: 1014 additions & 170 deletions

File tree

.github/actions/setup-deps/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runs:
1515
run: |
1616
brew update
1717
brew install llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} bdw-gc openssl libffi libuv
18-
brew link --overwrite lld@${{inputs.llvm-version}} libffi
18+
brew link --overwrite llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} libffi
1919
echo "$(brew --prefix llvm@${{inputs.llvm-version}})/bin" >> $GITHUB_PATH
2020
2121
# Install optional deps for demos.
@@ -35,7 +35,7 @@ runs:
3535
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
3636
sudo apt-get update
3737
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
38-
echo "/usr/lib/llvm-${{inputs.llvm-version}}/bin" >> $GITHUB_PATH
38+
echo "PATH=/usr/lib/llvm-${{inputs.llvm-version}}/bin:$PATH" >> $GITHUB_ENV
3939
4040
# Install optional deps for demos.
4141
#

.github/workflows/doc.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Docs
22

33
on:
44
push:
5-
branches: [ "**" ]
5+
branches: ["**"]
66
pull_request:
7-
branches: [ "**" ]
7+
branches: ["**"]
88

99
jobs:
1010
doc_verify:
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Node.js
1616
uses: actions/setup-node@v4
1717
with:
18-
node-version: '20'
18+
node-version: "20"
1919

2020
- name: Install embedme
2121
run: npm install -g embedme
@@ -43,7 +43,7 @@ jobs:
4343
- name: Set up Go
4444
uses: ./.github/actions/setup-go
4545
with:
46-
go-version: '1.23.6'
46+
go-version: "1.24.2"
4747

4848
- name: Install dependencies on macOS
4949
if: startsWith(matrix.os, 'macos')
@@ -79,7 +79,7 @@ jobs:
7979
- name: Set up Go
8080
uses: actions/setup-go@v5
8181
with:
82-
go-version: '1.23'
82+
go-version: "1.23"
8383

8484
- name: Install dependencies on macOS
8585
if: startsWith(matrix.os, 'macos')
@@ -130,7 +130,7 @@ jobs:
130130
- name: Set up Go
131131
uses: actions/setup-go@v5
132132
with:
133-
go-version: '1.23'
133+
go-version: "1.23"
134134

135135
- name: Install dependencies on macOS
136136
if: startsWith(matrix.os, 'macos')
@@ -145,6 +145,7 @@ jobs:
145145
set -e
146146
set -x
147147
source doc/_readme/scripts/install_ubuntu.sh
148+
echo "PATH=/usr/lib/llvm-19/bin:$PATH" >> $GITHUB_ENV
148149
149150
- name: Install llgo with tools
150151
run: |

.github/workflows/fmt.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Format Check
22

33
on:
44
push:
5-
branches: [ "**" ]
5+
branches: ["**"]
66
pull_request:
7-
branches: [ "**" ]
7+
branches: ["**"]
88

99
jobs:
1010
fmt:
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Go
1616
uses: ./.github/actions/setup-go
1717
with:
18-
go-version: '1.24.0'
18+
go-version: "1.24.2"
1919

2020
- name: Check formatting
2121
run: |

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Set up Go
3636
uses: ./.github/actions/setup-go
3737
with:
38-
go-version: "1.24.0"
38+
go-version: "1.24.2"
3939

4040
- name: Build
4141
run: go build -v ./...

.github/workflows/llgo.yml

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- macos-latest
3535
- ubuntu-24.04
3636
llvm: [19]
37-
go: ['1.21.13', '1.22.12', '1.23.6', '1.24.0']
37+
go: ["1.21.13", "1.22.12", "1.23.6", "1.24.2"]
3838
runs-on: ${{matrix.os}}
3939
steps:
4040
- uses: actions/checkout@v4
@@ -58,7 +58,7 @@ jobs:
5858
- name: Set up Go for build
5959
uses: ./.github/actions/setup-go
6060
with:
61-
go-version: "1.24.0"
61+
go-version: "1.24.2"
6262

6363
- name: Install
6464
run: |
@@ -105,7 +105,7 @@ jobs:
105105
- macos-latest
106106
- ubuntu-24.04
107107
llvm: [19]
108-
go: ["1.24.0"]
108+
go: ["1.24.2"]
109109
runs-on: ${{matrix.os}}
110110
steps:
111111
- uses: actions/checkout@v4
@@ -124,7 +124,7 @@ jobs:
124124
- name: Set up Go for build
125125
uses: ./.github/actions/setup-go
126126
with:
127-
go-version: "1.24.0"
127+
go-version: "1.24.2"
128128

129129
- name: Install
130130
run: |
@@ -146,7 +146,7 @@ jobs:
146146
matrix:
147147
os: [ubuntu-24.04, macos-latest]
148148
llvm: [19]
149-
go: ['1.21.13', '1.22.12', '1.23.6', '1.24.0']
149+
go: ["1.21.13", "1.22.12", "1.23.6", "1.24.2"]
150150
runs-on: ${{matrix.os}}
151151
steps:
152152
- uses: actions/checkout@v4
@@ -158,7 +158,7 @@ jobs:
158158
- name: Set up Go 1.23 for building llgo
159159
uses: ./.github/actions/setup-go
160160
with:
161-
go-version: "1.24.0"
161+
go-version: "1.24.2"
162162

163163
- name: Install llgo
164164
run: |
@@ -197,3 +197,50 @@ jobs:
197197
with:
198198
go-version: ${{matrix.go}}
199199
mod-version: "1.24"
200+
201+
cross-compile:
202+
continue-on-error: true
203+
strategy:
204+
matrix:
205+
os: [macos-latest]
206+
llvm: [19]
207+
runs-on: ${{matrix.os}}
208+
steps:
209+
- uses: actions/checkout@v4
210+
- name: Install dependencies
211+
uses: ./.github/actions/setup-deps
212+
with:
213+
llvm-version: ${{matrix.llvm}}
214+
215+
- name: Set up Go for building llgo
216+
uses: ./.github/actions/setup-go
217+
with:
218+
go-version: "1.24.2"
219+
220+
- name: Install wasmtime and wasi-libc
221+
run: |
222+
brew install wasmtime
223+
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/libclang_rt.builtins-wasm32-wasi-25.0.tar.gz
224+
tar -xvf libclang_rt.builtins-wasm32-wasi-25.0.tar.gz
225+
mkdir -p `llvm-config --libdir`/clang/19/lib/wasi/
226+
mv libclang_rt.builtins-wasm32-wasi-25.0/libclang_rt.builtins-wasm32.a `llvm-config --libdir`/clang/19/lib/wasi/
227+
228+
- name: Install llgo
229+
run: |
230+
go install ./...
231+
echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
232+
233+
- name: Test Cross Compilation (wasm)
234+
shell: bash
235+
working-directory: _demo
236+
run: |
237+
echo "Testing cross-compilation wasm with Go 1.24.2"
238+
239+
# Compile for wasm architecture
240+
GOOS=wasip1 GOARCH=wasm llgo build -o hello -v ./helloc
241+
242+
# Check file type
243+
file hello.wasm
244+
245+
# Run the wasm binary using llgo_wasm
246+
wasmtime hello.wasm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Follow these steps to generate the `llgo` command (its usage is the same as the
361361
brew update
362362
brew install llvm@19 lld@19 bdw-gc openssl cjson libffi libuv pkg-config
363363
brew install [email protected] # optional
364-
brew link --overwrite lld@19 libffi
364+
brew link --overwrite llvm@19 lld@19 libffi
365365
# curl https://raw.githubusercontent.com/goplus/llgo/refs/heads/main/install.sh | bash
366366
./install.sh
367367
```

_demo/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/goplus/llgo/_demo
22

33
go 1.20
44

5-
require github.com/goplus/lib v0.1.0
5+
require github.com/goplus/lib v0.2.0

_demo/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/goplus/lib v0.1.0 h1:kqMAC6FmVPfrw0q8E5yF6Y12WC4GOfi2L/MYS4QoxbQ=
2-
github.com/goplus/lib v0.1.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
1+
github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g=
2+
github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=

_demo/helloc/helloc.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"unsafe"
5+
6+
"github.com/goplus/lib/c"
7+
)
8+
9+
func main() {
10+
c.Printf(c.Str("Hello world by c.Printf\n"))
11+
c.Printf(c.Str("%ld\n"), unsafe.Sizeof(int(0)))
12+
c.Printf(c.Str("%ld\n"), unsafe.Sizeof(uintptr(0)))
13+
// var v any = int(0)
14+
// c.Printf(c.Str("%ld\n"), unsafe.Sizeof(v))
15+
}

_pydemo/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/goplus/llgo/_pydemo
22

33
go 1.20
44

5-
require github.com/goplus/lib v0.1.0
5+
require github.com/goplus/lib v0.2.0

0 commit comments

Comments
 (0)