Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cgo support for NetBSD #268

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

TotallyGamerJet
Copy link
Collaborator

What issue is this addressing?

Updates #249

What type of issue is this addressing?

feature

What this PR does | solves

Allows compiling with purego on NetBSD when there is a C compiler

@@ -54,7 +54,7 @@ func buildSharedLib(compilerEnv, libFile string, sources ...string) error {
}

var args []string
if runtime.GOOS == "freebsd" {
if runtime.GOOS == "freebsd" || runtime.GOOS == "netbsd" {
args = []string{"-shared", "-Wall", "-Werror", "-fPIC", "-o", libFile}
} else {
args = []string{"-shared", "-Wall", "-Werror", "-o", libFile}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, can't we use -fPIC for other platforms than FreeBSD and NetBSD?

.github/workflows/test.yml Outdated Show resolved Hide resolved
echo "=> go test race"
go test -race -shuffle=on -v -count=10 ./...
fi
netbsd:
Copy link
Member

@hajimehoshi hajimehoshi Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add to build tests for NetBSD in other platforms (e.g. Can we build a NetBSD binary in FreeBSD?)

            # Check cross-compiling NetBSD binaries.
            env GOOS=netbsd GOARCH=amd64 go build -v ./...
            env GOOS=netbsd GOARCH=arm64 go build -v ./...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's possible. We'd need to explicitly enable cgo since it's a cross compile. I'll try once the build in NetBSD is working

@TotallyGamerJet
Copy link
Collaborator Author

@0-wiz-0 I'm trying to finish up this PR so it can be merged but I can't figure out how to install go in the NetBSD environment. Could you look at the test.yml file?

@0-wiz-0
Copy link

0-wiz-0 commented Oct 15, 2024

Thank you for working on this, @TotallyGamerJet !
I looked at test.yml. You are using the upstream go binaries. They are distributed in a standard tarball, not as a pkgsrc package, so just unpack the tarball and use it - do not use pkg_add.
A prepare step like this should probably work:

          prepare: |
            ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz
            rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz
            ln -s /usr/local/go/bin/go /usr/local/bin

(Btw, cross-compilation to NetBSD should also work as usual in go.)

@TotallyGamerJet
Copy link
Collaborator Author

TotallyGamerJet commented Oct 15, 2024

Thanks for the help. I'm getting some weird error when opening the archive. Thoughts?

(Btw, cross-compilation to NetBSD should also work as usual in go.)

This PR currently only supports Cgo. Once I get it in a usable state I can work on getting the entirely go version working which would enable cross compiling

@0-wiz-0
Copy link

0-wiz-0 commented Oct 15, 2024

I see:

 ln -s /usr/local/go/bin/go /usr/local/bin
  /usr/bin/bash /home/runner/work/_actions/vmactions/netbsd-vm/v1/run.sh execSSHSH
  Config file: netbsd-10.0.conf
  FFFFFFFFFFFFFFFF:error:0A000126:SSL routines:ssl3_read_n:unexpected eof while reading:/usr/src/crypto/external/bsd/openssl/dist/ssl/record/rec_layer_s3.c:303:

you can ignore this, it's a bogus warning that will be fixed in 10.1.

  tar: could not chdir to '/usr/local'
  
  ln: /usr/local/bin: No such file or directory

Seems we need to add

mkdir /usr/local

before the tar command.
I didn't know that the target directory needed to exist first, sorry.

@0-wiz-0
Copy link

0-wiz-0 commented Oct 15, 2024

I just saw the CI run failure - some part of the process tries running /usr/bin/bash but that is not a default shell on NetBSD.
NetBSD provides /bin/sh, /bin/csh, and /bin/ksh, any of which is probably enough for doing CI stuff.
(Bash is installable as a package, if it's really needed.)

@TotallyGamerJet
Copy link
Collaborator Author

Not sure what exactly I did to fix it but it's workin now! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants