From b1fcae5cec5d0875eb134ad6291b746c581153e9 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 24 Nov 2024 19:03:47 +0800 Subject: [PATCH 1/4] cgo: only scan non-directories and ignore *_test.c --- internal/build/cgo.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/build/cgo.go b/internal/build/cgo.go index 4443596b..9615a73b 100644 --- a/internal/build/cgo.go +++ b/internal/build/cgo.go @@ -188,11 +188,18 @@ func parseCgo_(pkg *aPackage, files []*ast.File) (cfiles []string, preambles []c dirs[dir] = none{} } for dir := range dirs { - files, err := filepath.Glob(filepath.Join(dir, "*.c")) + matches, err := filepath.Glob(filepath.Join(dir, "*.c")) if err != nil { continue } - cfiles = append(cfiles, files...) + for _, match := range matches { + if strings.HasSuffix(match, "_test.c") { + continue + } + if fi, err := os.Stat(match); err == nil && !fi.IsDir() { + cfiles = append(cfiles, match) + } + } } for _, file := range files { From 56e9dab2ce8917c13a549fc432be7de34a498235 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 24 Nov 2024 20:02:23 +0800 Subject: [PATCH 2/4] ci: test demo with python 3.12 --- .github/workflows/go.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 13b31da4..98fa0ba7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - + - name: Set up Go uses: actions/setup-go@v5 with: @@ -115,12 +115,12 @@ jobs: run: | echo "Test result on ${{matrix.os}} with LLVM ${{matrix.llvm}}" > result.md bash .github/workflows/test_llgo.sh - + - name: chore/_xtool build tests run: | cd chore/_xtool llgo build -v ./... - + - name: LLDB tests if: ${{startsWith(matrix.os, 'macos')}} run: | @@ -129,7 +129,17 @@ jobs: - name: Test demos continue-on-error: true - run: bash .github/workflows/test_demo.sh + run: | + # TODO(lijie): force python3-embed to be linked with python-3.12-embed + # Currently, python3-embed is python-3.13-embed, doesn't work with pytorch + # Will remove this after pytorch is fixed. + pcdir=$HOME/pc + mkdir -p $pcdir + libdir=$(pkg-config --variable=libdir python-3.12-embed) + echo "libdir: $libdir" + ln -s $libdir/pkgconfig/python-3.12-embed.pc $pcdir/python3-embed.pc + export PKG_CONFIG_PATH=$pcdir + bash .github/workflows/test_demo.sh - name: Show test result run: cat result.md From f26c28354148968cbd02ace2e8db6b25e3925dec Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 24 Nov 2024 20:41:32 +0800 Subject: [PATCH 3/4] ci: enable demo result checking --- .github/workflows/go.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 98fa0ba7..3ecb5f67 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -128,7 +128,6 @@ jobs: bash _lldb/runtest.sh -v - name: Test demos - continue-on-error: true run: | # TODO(lijie): force python3-embed to be linked with python-3.12-embed # Currently, python3-embed is python-3.13-embed, doesn't work with pytorch From 1ba3474a5a06efa63092335883a9301a1204228a Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sun, 24 Nov 2024 23:50:59 +0800 Subject: [PATCH 4/4] lib: impl syscall.Faccesat --- internal/lib/syscall/syscall_linux.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/lib/syscall/syscall_linux.go b/internal/lib/syscall/syscall_linux.go index ee097f35..9451443a 100644 --- a/internal/lib/syscall/syscall_linux.go +++ b/internal/lib/syscall/syscall_linux.go @@ -15,6 +15,7 @@ import ( _ "unsafe" "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/os" "github.com/goplus/llgo/c/syscall" ) @@ -114,7 +115,14 @@ func Pipe2(p []int, flags int) error { // ----------------------------------------------------------------------------- func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { - panic("todo: syscall.Faccessat") + ret := faccessat(c.Int(dirfd), c.AllocaCStr(path), c.Int(mode), c.Int(flags)) + if ret != 0 { + return Errno(os.Errno()) + } + return nil } +//go:linkname faccessat C.faccessat +func faccessat(dirfd c.Int, path *c.Char, mode c.Int, flags c.Int) c.Int + // -----------------------------------------------------------------------------