Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f38338c58 | ||
|
|
8c76436d81 | ||
|
|
0e71576265 | ||
|
|
71b34003ca | ||
|
|
2c417d75a2 | ||
|
|
74ededd8c8 | ||
|
|
a732fa237c | ||
|
|
fd4c22308d | ||
|
|
d6f18894e6 | ||
|
|
992d54693f | ||
|
|
9be1bd0775 | ||
|
|
29cc689abd | ||
|
|
39d28e507d | ||
|
|
eacb5bc6f8 | ||
|
|
19658454bd | ||
|
|
02e3a6ae8b | ||
|
|
77376087db | ||
|
|
52a77f9efb |
2
.github/workflows/doc.yml
vendored
2
.github/workflows/doc.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
||||
id: lychee
|
||||
uses: lycheeverse/lychee-action@v2
|
||||
with:
|
||||
args: README.md
|
||||
args: --max-concurrency 3 --retry-wait-time 15 README.md
|
||||
|
||||
remote_install:
|
||||
strategy:
|
||||
|
||||
24
.github/workflows/llgo.yml
vendored
24
.github/workflows/llgo.yml
vendored
@@ -10,7 +10,23 @@ on:
|
||||
branches: [ "**" ]
|
||||
|
||||
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:
|
||||
needs: download-model
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -26,9 +42,13 @@ jobs:
|
||||
uses: ./.github/actions/setup-deps
|
||||
with:
|
||||
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
|
||||
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
|
||||
@@ -112,7 +132,6 @@ jobs:
|
||||
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
|
||||
@@ -146,6 +165,7 @@ jobs:
|
||||
|
||||
- name: run llgo test
|
||||
run: |
|
||||
llgo test ./...
|
||||
cd _demo
|
||||
llgo test -v ./runtest
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#if defined(__linux__)
|
||||
#define UNW_LOCAL_ONLY
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <features.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -3,7 +3,7 @@ module github.com/goplus/llgo/compiler
|
||||
go 1.22.0
|
||||
|
||||
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/runtime v0.0.0-00010101000000-000000000000
|
||||
github.com/goplus/llvm v0.8.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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/goplus/gogen v1.16.6 h1:Zwv18HoTbPDk8s2ajxgVeqZE5i4/GMV722KHl6GS8Yk=
|
||||
github.com/goplus/gogen v1.16.6/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
|
||||
github.com/goplus/gogen v1.16.8 h1:idakC+4OZIAvDSi3wkPGHlhpNEd7xkmvodXDMDvfn4s=
|
||||
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/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4=
|
||||
github.com/goplus/mod v0.13.17 h1:aWp14xosENrh7t0/0qcIejDmQEiTgI3ou2+KoLDlSlE=
|
||||
|
||||
@@ -175,6 +175,14 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
}
|
||||
case ModeRun:
|
||||
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 {
|
||||
fmt.Fprintln(os.Stderr, "clang", args)
|
||||
}
|
||||
err = ctx.env.Clang().Exec(args...)
|
||||
err = ctx.env.Clang().Link(args...)
|
||||
check(err)
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
if IsRpathChangeEnabled() && runtime.GOOS == "darwin" {
|
||||
dylibDeps := make([]string, 0, len(libs))
|
||||
for _, lib := range libs {
|
||||
dylibDep := findDylibDep(app, lib)
|
||||
@@ -746,6 +754,7 @@ const llgoDebug = "LLGO_DEBUG"
|
||||
const llgoTrace = "LLGO_TRACE"
|
||||
const llgoOptimize = "LLGO_OPTIMIZE"
|
||||
const llgoCheck = "LLGO_CHECK"
|
||||
const llgoRpathChange = "LLGO_RPATH_CHANGE"
|
||||
|
||||
func isEnvOn(env string, defVal bool) bool {
|
||||
envVal := strings.ToLower(os.Getenv(env))
|
||||
@@ -771,6 +780,10 @@ func IsCheckEnable() bool {
|
||||
return isEnvOn(llgoCheck, false)
|
||||
}
|
||||
|
||||
func IsRpathChangeEnabled() bool {
|
||||
return isEnvOn(llgoRpathChange, false)
|
||||
}
|
||||
|
||||
func ParseArgs(args []string, swflags map[string]bool) (flags, patterns []string, verbose bool) {
|
||||
n := len(args)
|
||||
for i := 0; i < n; i++ {
|
||||
@@ -857,7 +870,7 @@ func clFile(ctx *context, args []string, cFile, expFile string, procFile func(li
|
||||
if verbose {
|
||||
fmt.Fprintln(os.Stderr, "clang", args)
|
||||
}
|
||||
err := ctx.env.Clang().Exec(args...)
|
||||
err := ctx.env.Clang().Compile(args...)
|
||||
check(err)
|
||||
procFile(llFile)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package buildtags
|
||||
|
||||
import (
|
||||
|
||||
3
compiler/internal/env/env_test.go
vendored
3
compiler/internal/env/env_test.go
vendored
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package env
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -387,14 +387,13 @@ func (p Program) NewPackage(name, pkgPath string) Package {
|
||||
pyobjs := make(map[string]PyObjRef)
|
||||
pymods := make(map[string]Global)
|
||||
strs := make(map[string]llvm.Value)
|
||||
goStrs := make(map[string]llvm.Value)
|
||||
chkabi := make(map[types.Type]bool)
|
||||
glbDbgVars := make(map[Expr]bool)
|
||||
// Don't need reset p.needPyInit here
|
||||
// p.needPyInit = false
|
||||
ret := &aPackage{
|
||||
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,
|
||||
di: nil, cu: nil, glbDbgVars: glbDbgVars,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package ssatest
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package abi
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#if defined(__linux__)
|
||||
#define UNW_LOCAL_ONLY
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <features.h>
|
||||
#endif
|
||||
|
||||
|
||||
21
test/c_test.go
Normal file
21
test/c_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -40,6 +41,32 @@ func New(app string) *Cmd {
|
||||
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.
|
||||
func (p *Cmd) Exec(args ...string) error {
|
||||
cmd := exec.Command(p.app, args...)
|
||||
|
||||
Reference in New Issue
Block a user