Compare commits

...

18 Commits

Author SHA1 Message Date
xushiwei
9f38338c58 Merge pull request #1032 from cpunion/fix-linking
Remove LLVM runtime depencendy, better c toolchain integration
2025-03-20 15:47:43 +08:00
Li Jie
8c76436d81 ci: limit concurrency of doc links checker 2025-03-20 12:45:05 +08:00
Li Jie
0e71576265 build: pass CFLAGS and LDFLAGS to clang 2025-03-20 11:17:27 +08:00
Li Jie
71b34003ca debug: rollback unwind to don't depends llvm runtime, solve libunwind linking on homebrew linux in llgo formal 2025-03-19 14:32:32 +08:00
xushiwei
2c417d75a2 Merge pull request #1030 from cpunion/run-llgo-test
ci: run llgo test
2025-03-19 12:47:31 +08:00
Li Jie
74ededd8c8 ci: run llgo test ./... 2025-03-19 11:35:52 +08:00
Li Jie
a732fa237c test: reduce unnecessary pkgs compilation for llgo test 2025-03-19 11:35:51 +08:00
Li Jie
fd4c22308d ssa: removed unused ssa.Program.goStrs 2025-03-19 11:25:51 +08:00
Li Jie
d6f18894e6 test: add llgo build tag to compiler test cases 2025-03-19 11:25:50 +08:00
xushiwei
992d54693f Merge pull request #1029 from visualfc/gogen
update gogen v1.16.8
2025-03-19 08:51:12 +08:00
visualfc
9be1bd0775 update gogen 2025-03-19 08:32:00 +08:00
xushiwei
29cc689abd Merge pull request #1023 from cpunion/toggle-rpath-change
link: don't run install_name_tool -change by default
2025-03-13 23:15:47 +08:00
xushiwei
39d28e507d Merge pull request #1022 from goplus/dependabot/go_modules/compiler/github.com/goplus/gogen-1.16.7
build(deps): bump github.com/goplus/gogen from 1.16.6 to 1.16.7 in /compiler
2025-03-13 23:12:38 +08:00
Li Jie
eacb5bc6f8 link: don't run install_name_tool -change by default 2025-03-13 19:55:48 +08:00
dependabot[bot]
19658454bd build(deps): bump github.com/goplus/gogen in /compiler
Bumps [github.com/goplus/gogen](https://github.com/goplus/gogen) from 1.16.6 to 1.16.7.
- [Release notes](https://github.com/goplus/gogen/releases)
- [Commits](https://github.com/goplus/gogen/compare/v1.16.6...v1.16.7)

---
updated-dependencies:
- dependency-name: github.com/goplus/gogen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-13 00:17:09 +00:00
xushiwei
02e3a6ae8b Merge pull request #1018 from cpunion/fix-libunwind
runtime: fix libunwind to compatible with homebrew linux
2025-03-04 19:46:35 +08:00
Li Jie
77376087db ci: optimize model download to avoid Huggingface blocking
Download the LLaMA model as a separate job and share it as an artifact to prevent
repeated downloads from Huggingface which could lead to rate limiting or blocking.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-04 11:20:16 +08:00
Li Jie
52a77f9efb runtime: fix libunwind to compatible with homebrew linux 2025-03-04 10:52:18 +08:00
24 changed files with 137 additions and 11 deletions

View File

@@ -27,7 +27,7 @@ jobs:
id: lychee id: lychee
uses: lycheeverse/lychee-action@v2 uses: lycheeverse/lychee-action@v2
with: with:
args: README.md args: --max-concurrency 3 --retry-wait-time 15 README.md
remote_install: remote_install:
strategy: strategy:

View File

@@ -10,7 +10,23 @@ on:
branches: [ "**" ] branches: [ "**" ]
jobs: jobs:
download-model:
runs-on: ubuntu-latest
steps:
- name: Download model file
run: |
mkdir -p ./_demo/llama2-c
wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
- name: Upload model as artifact
uses: actions/upload-artifact@v4
with:
name: llama2-model
path: ./_demo/llama2-c/stories15M.bin
retention-days: 1
llgo: llgo:
needs: download-model
continue-on-error: true continue-on-error: true
strategy: strategy:
matrix: matrix:
@@ -26,9 +42,13 @@ jobs:
uses: ./.github/actions/setup-deps uses: ./.github/actions/setup-deps
with: with:
llvm-version: ${{matrix.llvm}} llvm-version: ${{matrix.llvm}}
- name: Download model artifact
uses: actions/download-artifact@v4
with:
name: llama2-model
path: ./_demo/llama2-c/
- name: Install further optional dependencies for demos - name: Install further optional dependencies for demos
run: | run: |
wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
py_deps=( py_deps=(
numpy # for github.com/goplus/llgo/py/numpy numpy # for github.com/goplus/llgo/py/numpy
torch # for github.com/goplus/llgo/py/torch torch # for github.com/goplus/llgo/py/torch
@@ -112,7 +132,6 @@ jobs:
llvm-version: ${{matrix.llvm}} llvm-version: ${{matrix.llvm}}
- name: Install further optional dependencies for demos - name: Install further optional dependencies for demos
run: | run: |
wget -P ./_demo/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
py_deps=( py_deps=(
numpy # for github.com/goplus/llgo/py/numpy numpy # for github.com/goplus/llgo/py/numpy
torch # for github.com/goplus/llgo/py/torch torch # for github.com/goplus/llgo/py/torch
@@ -146,6 +165,7 @@ jobs:
- name: run llgo test - name: run llgo test
run: | run: |
llgo test ./...
cd _demo cd _demo
llgo test -v ./runtest llgo test -v ./runtest

View File

@@ -1,6 +1,8 @@
#if defined(__linux__) #if defined(__linux__)
#define UNW_LOCAL_ONLY #define UNW_LOCAL_ONLY
#ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif
#include <features.h> #include <features.h>
#endif #endif

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package main package main
import ( import (

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package main package main
import ( import (

View File

@@ -3,7 +3,7 @@ module github.com/goplus/llgo/compiler
go 1.22.0 go 1.22.0
require ( require (
github.com/goplus/gogen v1.16.6 github.com/goplus/gogen v1.16.8
github.com/goplus/llgo v0.9.9 github.com/goplus/llgo v0.9.9
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.1 github.com/goplus/llvm v0.8.1

View File

@@ -1,7 +1,7 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 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/gogen v1.16.6 h1:Zwv18HoTbPDk8s2ajxgVeqZE5i4/GMV722KHl6GS8Yk= github.com/goplus/gogen v1.16.8 h1:idakC+4OZIAvDSi3wkPGHlhpNEd7xkmvodXDMDvfn4s=
github.com/goplus/gogen v1.16.6/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8= github.com/goplus/gogen v1.16.8/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
github.com/goplus/llvm v0.8.1 h1:Wrc9S8bKDhLjxjPuhnrgDYLRaFfKotOGt3zpId3LBmI= github.com/goplus/llvm v0.8.1 h1:Wrc9S8bKDhLjxjPuhnrgDYLRaFfKotOGt3zpId3LBmI=
github.com/goplus/llvm v0.8.1/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4= github.com/goplus/llvm v0.8.1/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4=
github.com/goplus/mod v0.13.17 h1:aWp14xosENrh7t0/0qcIejDmQEiTgI3ou2+KoLDlSlE= github.com/goplus/mod v0.13.17 h1:aWp14xosENrh7t0/0qcIejDmQEiTgI3ou2+KoLDlSlE=

View File

@@ -175,6 +175,14 @@ func Do(args []string, conf *Config) ([]Package, error) {
} }
case ModeRun: case ModeRun:
return nil, fmt.Errorf("cannot run multiple packages") return nil, fmt.Errorf("cannot run multiple packages")
case ModeTest:
newInitial := make([]*packages.Package, 0, len(initial))
for _, pkg := range initial {
if needLink(pkg, mode) {
newInitial = append(newInitial, pkg)
}
}
initial = newInitial
} }
} }
@@ -480,10 +488,10 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
if verbose { if verbose {
fmt.Fprintln(os.Stderr, "clang", args) fmt.Fprintln(os.Stderr, "clang", args)
} }
err = ctx.env.Clang().Exec(args...) err = ctx.env.Clang().Link(args...)
check(err) check(err)
if runtime.GOOS == "darwin" { if IsRpathChangeEnabled() && runtime.GOOS == "darwin" {
dylibDeps := make([]string, 0, len(libs)) dylibDeps := make([]string, 0, len(libs))
for _, lib := range libs { for _, lib := range libs {
dylibDep := findDylibDep(app, lib) dylibDep := findDylibDep(app, lib)
@@ -746,6 +754,7 @@ const llgoDebug = "LLGO_DEBUG"
const llgoTrace = "LLGO_TRACE" const llgoTrace = "LLGO_TRACE"
const llgoOptimize = "LLGO_OPTIMIZE" const llgoOptimize = "LLGO_OPTIMIZE"
const llgoCheck = "LLGO_CHECK" const llgoCheck = "LLGO_CHECK"
const llgoRpathChange = "LLGO_RPATH_CHANGE"
func isEnvOn(env string, defVal bool) bool { func isEnvOn(env string, defVal bool) bool {
envVal := strings.ToLower(os.Getenv(env)) envVal := strings.ToLower(os.Getenv(env))
@@ -771,6 +780,10 @@ func IsCheckEnable() bool {
return isEnvOn(llgoCheck, false) return isEnvOn(llgoCheck, false)
} }
func IsRpathChangeEnabled() bool {
return isEnvOn(llgoRpathChange, false)
}
func ParseArgs(args []string, swflags map[string]bool) (flags, patterns []string, verbose bool) { func ParseArgs(args []string, swflags map[string]bool) (flags, patterns []string, verbose bool) {
n := len(args) n := len(args)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
@@ -857,7 +870,7 @@ func clFile(ctx *context, args []string, cFile, expFile string, procFile func(li
if verbose { if verbose {
fmt.Fprintln(os.Stderr, "clang", args) fmt.Fprintln(os.Stderr, "clang", args)
} }
err := ctx.env.Clang().Exec(args...) err := ctx.env.Clang().Compile(args...)
check(err) check(err)
procFile(llFile) procFile(llFile)
} }

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package build package build
import ( import (

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package buildtags package buildtags
import ( import (

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package env package env
import ( import (

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -387,14 +387,13 @@ func (p Program) NewPackage(name, pkgPath string) Package {
pyobjs := make(map[string]PyObjRef) pyobjs := make(map[string]PyObjRef)
pymods := make(map[string]Global) pymods := make(map[string]Global)
strs := make(map[string]llvm.Value) strs := make(map[string]llvm.Value)
goStrs := make(map[string]llvm.Value)
chkabi := make(map[types.Type]bool) chkabi := make(map[types.Type]bool)
glbDbgVars := make(map[Expr]bool) glbDbgVars := make(map[Expr]bool)
// Don't need reset p.needPyInit here // Don't need reset p.needPyInit here
// p.needPyInit = false // p.needPyInit = false
ret := &aPackage{ ret := &aPackage{
mod: mod, vars: gbls, fns: fns, stubs: stubs, mod: mod, vars: gbls, fns: fns, stubs: stubs,
pyobjs: pyobjs, pymods: pymods, strs: strs, goStrs: goStrs, pyobjs: pyobjs, pymods: pymods, strs: strs,
chkabi: chkabi, Prog: p, chkabi: chkabi, Prog: p,
di: nil, cu: nil, glbDbgVars: glbDbgVars, di: nil, cu: nil, glbDbgVars: glbDbgVars,
} }

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package ssatest package ssatest
import ( import (

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
package abi package abi
import ( import (

View File

@@ -1,6 +1,8 @@
#if defined(__linux__) #if defined(__linux__)
#define UNW_LOCAL_ONLY #define UNW_LOCAL_ONLY
#ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif
#include <features.h> #include <features.h>
#endif #endif

21
test/c_test.go Normal file
View File

@@ -0,0 +1,21 @@
//go:build llgo
// +build llgo
package test
import (
"testing"
"github.com/goplus/llgo/c"
)
// Can't put it in c/ package because it is marked as 'decl'
func TestCstr(t *testing.T) {
cstr := c.Str("foo")
if cstr == nil {
t.Fatal("cstr() returned nil")
}
if c.Strlen(cstr) != 3 {
t.Fatal("cstr() returned invalid length")
}
}

View File

@@ -1,3 +1,6 @@
//go:build !llgo
// +build !llgo
/* /*
* Copyright (c) 2022 The GoPlus Authors (goplus.org). All rights reserved. * Copyright (c) 2022 The GoPlus Authors (goplus.org). All rights reserved.
* *

View File

@@ -20,6 +20,7 @@ import (
"io" "io"
"os" "os"
"os/exec" "os/exec"
"strings"
) )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -40,6 +41,32 @@ func New(app string) *Cmd {
return &Cmd{app, os.Stdout, os.Stderr} return &Cmd{app, os.Stdout, os.Stderr}
} }
func (p *Cmd) Compile(args ...string) error {
// Parse CFLAGS environment variable into separate arguments
cflags := strings.Fields(os.Getenv("CFLAGS"))
if len(cflags) > 0 {
// Create a new slice with capacity for all arguments
newArgs := make([]string, 0, len(cflags)+len(args))
newArgs = append(newArgs, cflags...)
newArgs = append(newArgs, args...)
args = newArgs
}
return p.Exec(args...)
}
func (p *Cmd) Link(args ...string) error {
// Parse LDFLAGS environment variable into separate arguments
ldflags := strings.Fields(os.Getenv("LDFLAGS"))
if len(ldflags) > 0 {
// Create a new slice with capacity for all arguments
newArgs := make([]string, 0, len(ldflags)+len(args))
newArgs = append(newArgs, ldflags...)
newArgs = append(newArgs, args...)
args = newArgs
}
return p.Exec(args...)
}
// Exec executes a clang command. // Exec executes a clang command.
func (p *Cmd) Exec(args ...string) error { func (p *Cmd) Exec(args ...string) error {
cmd := exec.Command(p.app, args...) cmd := exec.Command(p.app, args...)