gopy icon indicating copy to clipboard operation
gopy copied to clipboard

Incompatible with clang 19.1.7 (at least)

Open connorbrinton opened this issue 7 months ago • 3 comments

Trying to create a simple package produces the following error on macOS with a newer version of Clang installed:

❯ gopy pkg example.com/hello       
go build -v example.com/hello

--- Processing package: example.com/hello ---
gopy: skipping 'main' package "example.com/hello/hello"

--- building package ---
gopy pkg example.com/hello
goimports -w hello.go
go build -mod=mod -buildmode=c-shared -o hello_go.so .
/Users/connor/Code/scratch/scratch013/.venv/bin/python build.py
CGO_CFLAGS="-I/Users/connor/.pyenv/versions/3.13.0/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13" -fPIC -Ofast
CGO_LDFLAGS="-L/Users/connor/.pyenv/versions/3.13.0/lib" "-lpython3.13" -lintl -ldl -L/Users/connor/.pyenv/versions/3.13.0/lib -L/opt/homebrew/lib -Wl,-rpath,/opt/homebrew/lib -framework CoreFoundation
go build -mod=mod -buildmode=c-shared -o _hello.cpython-313-darwin.so .
cmd had error: exit status 1  output:
# runtime/cgo
clang: error: argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same behavior, or '-O3' to enable only conforming optimizations [-Werror,-Wdeprecated-ofast]

2025/04/30 11:04:07 error dispatching command: exit status 1

The Go package I'm trying to turn into a Python package consists of a single file, hello.go:

// hello is a simple package
package hello

import "fmt"

// Hello greets someone.
func Hello(name string) string {
	return fmt.Sprintf("hello %q from Go", name)
}

I believe that I'm using a newer version of Clang installed by Homebrew. This is my first time trying to use pygo, so I'm not sure which version of Clang introduced this incompatibility:

Homebrew clang version 19.1.7
Target: arm64-apple-darwin24.4.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/19.1.7_1/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin24.cfg

connorbrinton avatar Apr 30 '25 15:04 connorbrinton

If you need a way to build macOS wheels, checkout the cookiecutter I've created for gopy:

  • https://github.com/b-long/cookiecutter-gopy

macOS and Linux

Currently, this project works just fine for macOS and Linux. The build, test, and publishing all works and you can see real examples in the projects below.

Windows

I think the Windows code is quite close. It's commented out at the moment, but I don't believe it'll take much work to complete. Please, if anyone can offer any advice or suggest any changes, I would love to hear any/all ideas. 🙏

Projects based on this structure

My two projects (published to pypi.org) based on the above project structure are here:

  • https://github.com/b-long/ohpygossh
    • https://pypi.org/project/ohpygossh/
  • https://github.com/b-long/opentdf-python-sdk
    • https://pypi.org/project/otdf-python/

They are only pushing python 3.11 and 3.12 wheels, but since I'm using Github's matrix style builds, it only takes a line or two change to experiment.

Please feel free to open PRs or experiment with any of the above and please share any experimenting that you do publicly!

b-long avatar May 02 '25 00:05 b-long

@b-long I tried your template, but hit the same issue, what clang version are you using?

aotarola avatar May 15 '25 22:05 aotarola

@connorbrinton I got it working by downgrading to llvm@14

brew install llvm@14

aotarola avatar May 16 '25 00:05 aotarola

@aotarola Sorry for the slow reply, and sorry the cookiecutter didn't help. Absolutely open to any/all PRs on that project! 🙂

b-long avatar Aug 19 '25 00:08 b-long