Merge commit '7de4137d4678a3bcbd735f887028489f97f1e479' into embed-cmds
# Conflicts: # internal/build/build.go
This commit is contained in:
37
.github/actions/setup-goreleaser/action.yml
vendored
Normal file
37
.github/actions/setup-goreleaser/action.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: "Setup GoReleaser"
|
||||||
|
description: "Setup GoReleaser environment"
|
||||||
|
inputs:
|
||||||
|
darwin-cache-key:
|
||||||
|
description: "Darwin sysroot cache key"
|
||||||
|
required: true
|
||||||
|
linux-cache-key:
|
||||||
|
description: "Linux sysroot cache key"
|
||||||
|
required: true
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: 1.24.x
|
||||||
|
- name: Restore Darwin sysroot cache
|
||||||
|
id: cache-darwin-sysroot
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: .sysroot/darwin.tar.gz
|
||||||
|
key: ${{ inputs.darwin-cache-key }}
|
||||||
|
- name: Restore Linux sysroot cache
|
||||||
|
id: cache-linux-sysroot
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: .sysroot/linux.tar.gz
|
||||||
|
key: ${{ inputs.linux-cache-key }}
|
||||||
|
- name: Populate Darwin sysroot
|
||||||
|
run: tar -xzvf .sysroot/darwin.tar.gz -C .sysroot
|
||||||
|
shell: bash
|
||||||
|
- name: Populate Linux sysroot
|
||||||
|
run: tar -xzvf .sysroot/linux.tar.gz -C .sysroot
|
||||||
|
shell: bash
|
||||||
|
- name: Check file
|
||||||
|
run: tree .sysroot
|
||||||
|
shell: bash
|
||||||
28
.github/actions/test-helloworld/action.yml
vendored
28
.github/actions/test-helloworld/action.yml
vendored
@@ -1,11 +1,11 @@
|
|||||||
name: 'Test Hello World'
|
name: "Test Hello World"
|
||||||
description: 'Test Hello World with specific Go and module versions'
|
description: "Test Hello World with specific Go and module versions"
|
||||||
inputs:
|
inputs:
|
||||||
go-version:
|
go-version:
|
||||||
description: 'Go version being tested'
|
description: "Go version being tested"
|
||||||
required: true
|
required: true
|
||||||
mod-version:
|
mod-version:
|
||||||
description: 'Go module version to use'
|
description: "Go module version to use"
|
||||||
required: true
|
required: true
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
@@ -24,12 +24,30 @@ runs:
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goplus/lib/c"
|
"github.com/goplus/lib/c"
|
||||||
|
"github.com/goplus/lib/cpp/std"
|
||||||
)
|
)
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello, LLGo!")
|
fmt.Println("Hello, LLGo!")
|
||||||
println("Hello, LLGo!")
|
println("Hello, LLGo!")
|
||||||
c.Printf(c.Str("Hello, LLGo!\n"))
|
c.Printf(c.Str("Hello, LLGo!\n"))
|
||||||
|
c.Printf(std.Str("Hello LLGo by cpp/std.Str\n").CStr())
|
||||||
}
|
}
|
||||||
EOL
|
EOL
|
||||||
go mod tidy
|
go mod tidy
|
||||||
llgo run .
|
EXPECTED="Hello, LLGo!
|
||||||
|
Hello, LLGo!
|
||||||
|
Hello, LLGo!
|
||||||
|
Hello LLGo by cpp/std.Str"
|
||||||
|
OUTPUT=$(llgo run . 2>&1)
|
||||||
|
if echo "$OUTPUT" | grep -qF "$EXPECTED"; then
|
||||||
|
echo "Basic test passed"
|
||||||
|
else
|
||||||
|
echo "Basic test failed"
|
||||||
|
echo "Expected to contain:"
|
||||||
|
echo "$EXPECTED"
|
||||||
|
echo "Got:"
|
||||||
|
echo "$OUTPUT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#TODO(zzy): Test embed targets, need dispatch target dir
|
||||||
|
|||||||
4
.github/workflows/doc.yml
vendored
4
.github/workflows/doc.yml
vendored
@@ -2,7 +2,9 @@ name: Docs
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["**"]
|
branches:
|
||||||
|
- "**"
|
||||||
|
- "!dependabot/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/fmt.yml
vendored
4
.github/workflows/fmt.yml
vendored
@@ -2,7 +2,9 @@ name: Format Check
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["**"]
|
branches:
|
||||||
|
- "**"
|
||||||
|
- "!dependabot/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@@ -5,7 +5,9 @@ name: Go
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["**"]
|
branches:
|
||||||
|
- "**"
|
||||||
|
- "!dependabot/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/llgo.yml
vendored
4
.github/workflows/llgo.yml
vendored
@@ -5,7 +5,9 @@ name: LLGo
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["**"]
|
branches:
|
||||||
|
- "**"
|
||||||
|
- "!dependabot/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
|
|
||||||
|
|||||||
210
.github/workflows/release-build.yml
vendored
210
.github/workflows/release-build.yml
vendored
@@ -2,60 +2,228 @@ name: Release Build
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
branches: ["**"]
|
||||||
- "*"
|
tags: ["*"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["**"]
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
setup:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
darwin-cache-key: ${{ steps.cache-keys.outputs.darwin-key }}
|
||||||
|
linux-cache-key: ${{ steps.cache-keys.outputs.linux-key }}
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
- name: Calculate cache keys
|
||||||
|
id: cache-keys
|
||||||
|
run: |
|
||||||
|
DARWIN_KEY="darwin-sysroot-${{ hashFiles('.github/workflows/populate_darwin_sysroot.sh', '.github/workflows/release-build.yml') }}"
|
||||||
|
LINUX_KEY="linux-sysroot-${{ hashFiles('.github/workflows/populate_linux_sysroot.sh', '.github/workflows/release-build.yml') }}"
|
||||||
|
echo "darwin-key=$DARWIN_KEY" >> $GITHUB_OUTPUT
|
||||||
|
echo "linux-key=$LINUX_KEY" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
populate-darwin-sysroot:
|
populate-darwin-sysroot:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
needs: setup
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v5
|
||||||
|
- name: Check Darwin sysroot cache
|
||||||
|
id: cache-darwin-sysroot
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: .sysroot/darwin.tar.gz
|
||||||
|
key: ${{ needs.setup.outputs.darwin-cache-key }}
|
||||||
|
lookup-only: true
|
||||||
- name: Populate Darwin sysroot
|
- name: Populate Darwin sysroot
|
||||||
|
if: steps.cache-darwin-sysroot.outputs.cache-hit != 'true'
|
||||||
run: bash .github/workflows/populate_darwin_sysroot.sh
|
run: bash .github/workflows/populate_darwin_sysroot.sh
|
||||||
- name: Create Darwin sysroot tarball
|
- name: Create Darwin sysroot tarball
|
||||||
|
if: steps.cache-darwin-sysroot.outputs.cache-hit != 'true'
|
||||||
run: tar -czvf .sysroot/darwin.tar.gz -C .sysroot darwin
|
run: tar -czvf .sysroot/darwin.tar.gz -C .sysroot darwin
|
||||||
- name: Upload Darwin sysroot tarball
|
- name: Save Darwin sysroot cache
|
||||||
uses: actions/upload-artifact@v4
|
if: steps.cache-darwin-sysroot.outputs.cache-hit != 'true'
|
||||||
|
uses: actions/cache/save@v4
|
||||||
with:
|
with:
|
||||||
name: darwin-sysroot-tarball
|
|
||||||
path: .sysroot/darwin.tar.gz
|
path: .sysroot/darwin.tar.gz
|
||||||
compression-level: 0
|
key: ${{ needs.setup.outputs.darwin-cache-key }}
|
||||||
build:
|
populate-linux-sysroot:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: populate-darwin-sysroot
|
needs: setup
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v5
|
||||||
|
- name: Check Linux sysroot cache
|
||||||
|
id: cache-linux-sysroot
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
path: .sysroot/linux.tar.gz
|
||||||
- name: Set up Go
|
key: ${{ needs.setup.outputs.linux-cache-key }}
|
||||||
uses: actions/setup-go@v6
|
lookup-only: true
|
||||||
with:
|
|
||||||
go-version: 1.24.x
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
|
if: steps.cache-linux-sysroot.outputs.cache-hit != 'true'
|
||||||
with:
|
with:
|
||||||
image: tonistiigi/binfmt:qemu-v7.0.0-28
|
image: tonistiigi/binfmt:qemu-v7.0.0-28
|
||||||
- name: Download Darwin sysroot tarball
|
|
||||||
uses: actions/download-artifact@v5
|
|
||||||
with:
|
|
||||||
name: darwin-sysroot-tarball
|
|
||||||
path: .sysroot
|
|
||||||
- name: Populate Darwin sysroot
|
|
||||||
run: tar -xzvf .sysroot/darwin.tar.gz -C .sysroot
|
|
||||||
- name: Populate Linux sysroot
|
- name: Populate Linux sysroot
|
||||||
|
if: steps.cache-linux-sysroot.outputs.cache-hit != 'true'
|
||||||
run: bash .github/workflows/populate_linux_sysroot.sh
|
run: bash .github/workflows/populate_linux_sysroot.sh
|
||||||
- name: Run GoReleaser
|
- name: Create Linux sysroot tarball
|
||||||
|
if: steps.cache-linux-sysroot.outputs.cache-hit != 'true'
|
||||||
|
run: tar -czvf .sysroot/linux.tar.gz -C .sysroot linux
|
||||||
|
- name: Save Linux sysroot cache
|
||||||
|
if: steps.cache-linux-sysroot.outputs.cache-hit != 'true'
|
||||||
|
uses: actions/cache/save@v4
|
||||||
|
with:
|
||||||
|
path: .sysroot/linux.tar.gz
|
||||||
|
key: ${{ needs.setup.outputs.linux-cache-key }}
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [setup, populate-darwin-sysroot, populate-linux-sysroot]
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
- name: Set up Release
|
||||||
|
uses: ./.github/actions/setup-goreleaser
|
||||||
|
with:
|
||||||
|
darwin-cache-key: ${{ needs.setup.outputs.darwin-cache-key }}
|
||||||
|
linux-cache-key: ${{ needs.setup.outputs.linux-cache-key }}
|
||||||
|
- name: Run GoReleaser (Build & Test)
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{github.token}}
|
GITHUB_TOKEN: ${{github.token}}
|
||||||
run: |
|
run: |
|
||||||
|
docker run \
|
||||||
|
--rm \
|
||||||
|
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
-v $(pwd):/go/src/llgo \
|
||||||
|
-w /go/src/llgo \
|
||||||
|
ghcr.io/goreleaser/goreleaser-cross:v1.22 \
|
||||||
|
release --skip=publish,nfpm,snapcraft --snapshot --clean
|
||||||
|
|
||||||
|
- name: Upload Darwin AMD64 Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: llgo-darwin-amd64
|
||||||
|
path: .dist/*darwin-amd64.tar.gz
|
||||||
|
retention-days: 3
|
||||||
|
include-hidden-files: true
|
||||||
|
|
||||||
|
- name: Upload Darwin ARM64 Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: llgo-darwin-arm64
|
||||||
|
path: .dist/*darwin-arm64.tar.gz
|
||||||
|
retention-days: 3
|
||||||
|
include-hidden-files: true
|
||||||
|
|
||||||
|
- name: Upload Linux AMD64 Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: llgo-linux-amd64
|
||||||
|
path: .dist/*linux-amd64.tar.gz
|
||||||
|
retention-days: 3
|
||||||
|
include-hidden-files: true
|
||||||
|
|
||||||
|
- name: Upload Linux ARM64 Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: llgo-linux-arm64
|
||||||
|
path: .dist/*linux-arm64.tar.gz
|
||||||
|
retention-days: 3
|
||||||
|
include-hidden-files: true
|
||||||
|
|
||||||
|
- name: Upload Checksums
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: llgo-checksums
|
||||||
|
path: .dist/*checksums.txt
|
||||||
|
retention-days: 3
|
||||||
|
include-hidden-files: true
|
||||||
|
|
||||||
|
test-artifacts:
|
||||||
|
needs: build
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: macos-13
|
||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
go-version: "1.24.2"
|
||||||
|
go-mod-version: "1.24"
|
||||||
|
- os: macos-latest
|
||||||
|
goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
go-version: "1.24.2"
|
||||||
|
go-mod-version: "1.24"
|
||||||
|
- os: ubuntu-latest
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
go-version: "1.24.2"
|
||||||
|
go-mod-version: "1.24"
|
||||||
|
- os: ubuntu-24.04-arm
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
go-version: "1.24.2"
|
||||||
|
go-mod-version: "1.24"
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: ./.github/actions/setup-deps
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go-version }}
|
||||||
|
- name: Download Platform Artifact
|
||||||
|
uses: actions/download-artifact@v5
|
||||||
|
with:
|
||||||
|
name: llgo-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Extract LLGO Archive
|
||||||
|
run: |
|
||||||
|
echo "Looking for ${{ matrix.goos }}_${{ matrix.goarch }} archive..."
|
||||||
|
ARCHIVE=$(ls *.tar.gz | head -n1)
|
||||||
|
mkdir -p release-llgo
|
||||||
|
tar -xzf "$ARCHIVE" -C release-llgo
|
||||||
|
ls -la release-llgo/
|
||||||
|
echo "${{ github.workspace }}/release-llgo/bin/" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Test Hello World
|
||||||
|
uses: ./.github/actions/test-helloworld
|
||||||
|
with:
|
||||||
|
go-version: ${{matrix.go-version}}
|
||||||
|
mod-version: ${{ matrix.go-mod-version }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: [setup, build, test-artifacts]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up Release
|
||||||
|
uses: ./.github/actions/setup-goreleaser
|
||||||
|
with:
|
||||||
|
darwin-cache-key: ${{ needs.setup.outputs.darwin-cache-key }}
|
||||||
|
linux-cache-key: ${{ needs.setup.outputs.linux-cache-key }}
|
||||||
|
- name: Run GoReleaser (Release)
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{github.token}}
|
||||||
|
run: |
|
||||||
|
echo "Publishing release for tag: ${{ github.ref }}"
|
||||||
|
echo "All artifact tests passed, proceeding with release..."
|
||||||
docker run \
|
docker run \
|
||||||
--rm \
|
--rm \
|
||||||
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
|
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
|
||||||
|
|||||||
4
.github/workflows/targets.yml
vendored
4
.github/workflows/targets.yml
vendored
@@ -3,7 +3,9 @@ name: Targets
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["**"]
|
branches:
|
||||||
|
- "**"
|
||||||
|
- "!dependabot/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ var AbiMode int
|
|||||||
var CheckLinkArgs bool
|
var CheckLinkArgs bool
|
||||||
var CheckLLFiles bool
|
var CheckLLFiles bool
|
||||||
var GenLLFiles bool
|
var GenLLFiles bool
|
||||||
|
var ForceEspClang bool
|
||||||
|
|
||||||
func AddCommonFlags(fs *flag.FlagSet) {
|
func AddCommonFlags(fs *flag.FlagSet) {
|
||||||
fs.BoolVar(&Verbose, "v", false, "Verbose output")
|
fs.BoolVar(&Verbose, "v", false, "Verbose output")
|
||||||
@@ -47,6 +48,7 @@ func AddBuildFlags(fs *flag.FlagSet) {
|
|||||||
fs.BoolVar(&CheckLinkArgs, "check-linkargs", false, "check link args valid")
|
fs.BoolVar(&CheckLinkArgs, "check-linkargs", false, "check link args valid")
|
||||||
fs.BoolVar(&CheckLLFiles, "check-llfiles", false, "check .ll files valid")
|
fs.BoolVar(&CheckLLFiles, "check-llfiles", false, "check .ll files valid")
|
||||||
fs.BoolVar(&GenLLFiles, "gen-llfiles", false, "generate .ll files for pkg export")
|
fs.BoolVar(&GenLLFiles, "gen-llfiles", false, "generate .ll files for pkg export")
|
||||||
|
fs.BoolVar(&ForceEspClang, "force-espclang", false, "force to use esp-clang")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,5 +97,6 @@ func UpdateConfig(conf *build.Config) {
|
|||||||
conf.CheckLinkArgs = CheckLinkArgs
|
conf.CheckLinkArgs = CheckLinkArgs
|
||||||
conf.CheckLLFiles = CheckLLFiles
|
conf.CheckLLFiles = CheckLLFiles
|
||||||
conf.GenLL = GenLLFiles
|
conf.GenLL = GenLLFiles
|
||||||
|
conf.ForceEspClang = ForceEspClang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -6,7 +6,7 @@ toolchain go1.24.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/goplus/cobra v1.9.12 //gop:class
|
github.com/goplus/cobra v1.9.12 //gop:class
|
||||||
github.com/goplus/gogen v1.19.1
|
github.com/goplus/gogen v1.19.2
|
||||||
github.com/goplus/lib v0.3.0
|
github.com/goplus/lib v0.3.0
|
||||||
github.com/goplus/llgo/runtime v0.0.0-00010101000000-000000000000
|
github.com/goplus/llgo/runtime v0.0.0-00010101000000-000000000000
|
||||||
github.com/goplus/llvm v0.8.5
|
github.com/goplus/llvm v0.8.5
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -6,8 +6,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/goplus/cobra v1.9.12 h1:0F9EdEbeGyITGz+mqoHoJ5KpUw97p1CkxV74IexHw5s=
|
github.com/goplus/cobra v1.9.12 h1:0F9EdEbeGyITGz+mqoHoJ5KpUw97p1CkxV74IexHw5s=
|
||||||
github.com/goplus/cobra v1.9.12/go.mod h1:p4LhfNJDKEpiGjGiNn0crUXL5dUPA5DX2ztYpEJR34E=
|
github.com/goplus/cobra v1.9.12/go.mod h1:p4LhfNJDKEpiGjGiNn0crUXL5dUPA5DX2ztYpEJR34E=
|
||||||
github.com/goplus/gogen v1.19.1 h1:L7jz60azeowj8zUq48tozETriTPBLqHb0nDj6PheANc=
|
github.com/goplus/gogen v1.19.2 h1:0WCfbMy9V2gGIUG4gnlhbFkLLuEwVuxOgkzjJjeGsP0=
|
||||||
github.com/goplus/gogen v1.19.1/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
|
github.com/goplus/gogen v1.19.2/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
|
||||||
github.com/goplus/lib v0.3.0 h1:y0ZGb5Q/RikW1oMMB4Di7XIZIpuzh/7mlrR8HNbxXCA=
|
github.com/goplus/lib v0.3.0 h1:y0ZGb5Q/RikW1oMMB4Di7XIZIpuzh/7mlrR8HNbxXCA=
|
||||||
github.com/goplus/lib v0.3.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
github.com/goplus/lib v0.3.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||||
github.com/goplus/llvm v0.8.5 h1:DUnFeYC3Rco622tBEKGg8xkigRAV2fh5ZIfBCt7gOSs=
|
github.com/goplus/llvm v0.8.5 h1:DUnFeYC3Rco622tBEKGg8xkigRAV2fh5ZIfBCt7gOSs=
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ type Config struct {
|
|||||||
GenLL bool // generate pkg .ll files
|
GenLL bool // generate pkg .ll files
|
||||||
CheckLLFiles bool // check .ll files valid
|
CheckLLFiles bool // check .ll files valid
|
||||||
CheckLinkArgs bool // check linkargs valid
|
CheckLinkArgs bool // check linkargs valid
|
||||||
|
ForceEspClang bool // force to use esp-clang
|
||||||
Tags string
|
Tags string
|
||||||
GlobalNames map[string][]string // pkg => names
|
GlobalNames map[string][]string // pkg => names
|
||||||
GlobalDatas map[string]string // pkg.name => data
|
GlobalDatas map[string]string // pkg.name => data
|
||||||
@@ -192,7 +193,8 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
conf.AppExt = defaultAppExt(conf)
|
conf.AppExt = defaultAppExt(conf)
|
||||||
}
|
}
|
||||||
// Handle crosscompile configuration first to set correct GOOS/GOARCH
|
// Handle crosscompile configuration first to set correct GOOS/GOARCH
|
||||||
export, err := crosscompile.Use(conf.Goos, conf.Goarch, IsWasiThreadsEnabled(), conf.Target)
|
forceEspClang := conf.ForceEspClang || conf.Target != ""
|
||||||
|
export, err := crosscompile.Use(conf.Goos, conf.Goarch, conf.Target, IsWasiThreadsEnabled(), forceEspClang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to setup crosscompile: %w", err)
|
return nil, fmt.Errorf("failed to setup crosscompile: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func getMacOSSysroot() (string, error) {
|
|||||||
|
|
||||||
// getESPClangRoot returns the ESP Clang root directory, checking LLGoROOT first,
|
// getESPClangRoot returns the ESP Clang root directory, checking LLGoROOT first,
|
||||||
// then downloading if needed and platform is supported
|
// then downloading if needed and platform is supported
|
||||||
func getESPClangRoot() (clangRoot string, err error) {
|
func getESPClangRoot(forceEspClang bool) (clangRoot string, err error) {
|
||||||
llgoRoot := env.LLGoROOT()
|
llgoRoot := env.LLGoROOT()
|
||||||
|
|
||||||
// First check if clang exists in LLGoROOT
|
// First check if clang exists in LLGoROOT
|
||||||
@@ -114,6 +114,10 @@ func getESPClangRoot() (clangRoot string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !forceEspClang {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// Try to download ESP Clang if platform is supported
|
// Try to download ESP Clang if platform is supported
|
||||||
platformSuffix := getESPClangPlatform(runtime.GOOS, runtime.GOARCH)
|
platformSuffix := getESPClangPlatform(runtime.GOOS, runtime.GOARCH)
|
||||||
if platformSuffix != "" {
|
if platformSuffix != "" {
|
||||||
@@ -192,39 +196,39 @@ func getOrCompileWithConfig(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, err error) {
|
||||||
targetTriple := llvm.GetTargetTriple(goos, goarch)
|
targetTriple := llvm.GetTargetTriple(goos, goarch)
|
||||||
llgoRoot := env.LLGoROOT()
|
llgoRoot := env.LLGoROOT()
|
||||||
|
|
||||||
// Check for ESP Clang support for target-based builds
|
// Check for ESP Clang support for target-based builds
|
||||||
clangRoot, err := getESPClangRoot()
|
clangRoot, err := getESPClangRoot(forceEspClang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ClangRoot and CC if clang is available
|
// Set ClangRoot and CC if clang is available
|
||||||
export.ClangRoot = clangRoot
|
export.ClangRoot = clangRoot
|
||||||
|
if clangRoot != "" {
|
||||||
export.CC = filepath.Join(clangRoot, "bin", "clang++")
|
export.CC = filepath.Join(clangRoot, "bin", "clang++")
|
||||||
|
} else {
|
||||||
|
export.CC = "clang++"
|
||||||
|
}
|
||||||
|
|
||||||
if runtime.GOOS == goos && runtime.GOARCH == goarch {
|
if runtime.GOOS == goos && runtime.GOARCH == goarch {
|
||||||
clangLib := filepath.Join(clangRoot, "lib")
|
|
||||||
clangInc := filepath.Join(clangRoot, "include")
|
|
||||||
// not cross compile
|
// not cross compile
|
||||||
// Set up basic flags for non-cross-compile
|
// Set up basic flags for non-cross-compile
|
||||||
export.LDFLAGS = []string{
|
export.LDFLAGS = []string{
|
||||||
"-L" + clangLib,
|
|
||||||
"-target", targetTriple,
|
"-target", targetTriple,
|
||||||
"-Qunused-arguments",
|
"-Qunused-arguments",
|
||||||
"-Wno-unused-command-line-argument",
|
"-Wno-unused-command-line-argument",
|
||||||
"-Wl,--error-limit=0",
|
"-Wl,--error-limit=0",
|
||||||
"-fuse-ld=lld",
|
"-fuse-ld=lld",
|
||||||
}
|
}
|
||||||
|
if clangRoot != "" {
|
||||||
|
clangLib := filepath.Join(clangRoot, "lib")
|
||||||
|
clangInc := filepath.Join(clangRoot, "include")
|
||||||
export.CFLAGS = append(export.CFLAGS, "-I"+clangInc)
|
export.CFLAGS = append(export.CFLAGS, "-I"+clangInc)
|
||||||
export.CCFLAGS = []string{
|
export.LDFLAGS = append(export.LDFLAGS, "-L"+clangLib)
|
||||||
"-Qunused-arguments",
|
|
||||||
"-Wno-unused-command-line-argument",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add platform-specific rpath flags
|
// Add platform-specific rpath flags
|
||||||
switch goos {
|
switch goos {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
@@ -237,6 +241,11 @@ func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
|||||||
// For other Unix-like systems, try the generic rpath
|
// For other Unix-like systems, try the generic rpath
|
||||||
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
export.LDFLAGS = append(export.LDFLAGS, "-Wl,-rpath,"+clangLib)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
export.CCFLAGS = []string{
|
||||||
|
"-Qunused-arguments",
|
||||||
|
"-Wno-unused-command-line-argument",
|
||||||
|
}
|
||||||
|
|
||||||
// Add sysroot for macOS only
|
// Add sysroot for macOS only
|
||||||
if goos == "darwin" {
|
if goos == "darwin" {
|
||||||
@@ -272,7 +281,9 @@ func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
|||||||
"--gc-sections",
|
"--gc-sections",
|
||||||
"-lm",
|
"-lm",
|
||||||
"-latomic",
|
"-latomic",
|
||||||
"-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
|
// libpthread & libdl is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
|
||||||
|
"-lpthread",
|
||||||
|
"-ldl",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -429,7 +440,7 @@ func UseTarget(targetName string) (export Export, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for ESP Clang support for target-based builds
|
// Check for ESP Clang support for target-based builds
|
||||||
clangRoot, err := getESPClangRoot()
|
clangRoot, err := getESPClangRoot(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -634,9 +645,9 @@ func UseTarget(targetName string) (export Export, err error) {
|
|||||||
|
|
||||||
// Use extends the original Use function to support target-based configuration
|
// Use extends the original Use function to support target-based configuration
|
||||||
// If targetName is provided, it takes precedence over goos/goarch
|
// If targetName is provided, it takes precedence over goos/goarch
|
||||||
func Use(goos, goarch string, wasiThreads bool, targetName string) (export Export, err error) {
|
func Use(goos, goarch, targetName string, wasiThreads, forceEspClang bool) (export Export, err error) {
|
||||||
if targetName != "" && !strings.HasPrefix(targetName, "wasm") && !strings.HasPrefix(targetName, "wasi") {
|
if targetName != "" && !strings.HasPrefix(targetName, "wasm") && !strings.HasPrefix(targetName, "wasi") {
|
||||||
return UseTarget(targetName)
|
return UseTarget(targetName)
|
||||||
}
|
}
|
||||||
return use(goos, goarch, wasiThreads)
|
return use(goos, goarch, wasiThreads, forceEspClang)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ func TestUseCrossCompileSDK(t *testing.T) {
|
|||||||
goarch: runtime.GOARCH,
|
goarch: runtime.GOARCH,
|
||||||
expectSDK: true, // Changed: now we expect flags even for same platform
|
expectSDK: true, // Changed: now we expect flags even for same platform
|
||||||
expectCCFlags: true, // Changed: CCFLAGS will contain sysroot
|
expectCCFlags: true, // Changed: CCFLAGS will contain sysroot
|
||||||
expectCFlags: true, // Changed: CFLAGS will contain include paths
|
expectCFlags: false, // Changed: CFLAGS will not contain include paths
|
||||||
expectLDFlags: true, // Changed: LDFLAGS will contain library paths
|
expectLDFlags: false, // Changed: LDFLAGS will not contain library paths
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WASM Target",
|
name: "WASM Target",
|
||||||
@@ -76,7 +76,7 @@ func TestUseCrossCompileSDK(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
export, err := use(tc.goos, tc.goarch, false)
|
export, err := use(tc.goos, tc.goarch, false, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
@@ -280,7 +280,7 @@ func TestUseTarget(t *testing.T) {
|
|||||||
|
|
||||||
func TestUseWithTarget(t *testing.T) {
|
func TestUseWithTarget(t *testing.T) {
|
||||||
// Test target-based configuration takes precedence
|
// Test target-based configuration takes precedence
|
||||||
export, err := Use("linux", "amd64", false, "esp32")
|
export, err := Use("linux", "amd64", "esp32", false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ func TestUseWithTarget(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test fallback to goos/goarch when no target specified
|
// Test fallback to goos/goarch when no target specified
|
||||||
export, err = Use(runtime.GOOS, runtime.GOARCH, false, "")
|
export, err = Use(runtime.GOOS, runtime.GOARCH, "", false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user