gon2n icon indicating copy to clipboard operation
gon2n copied to clipboard

How to static compile edged & supernoded? any doc?

Open Droid-MAX opened this issue 3 years ago • 19 comments

Droid-MAX avatar Oct 13 '20 08:10 Droid-MAX

I compile edgectl & supernodectl successful, but when I compile edged & supernoded, prompt failed and miss n2n related files. then I search for n2n source code, and no idea about that, hope get sone help.

Droid-MAX avatar Oct 13 '20 08:10 Droid-MAX

Hi! Thanks for your issue. To compile gon2n, the headers for n2n need to be present. I implemented a go:generate line for it (see https://github.com/pojntfx/gon2n/blob/master/pkg/workers/supernode.go#L3); by running go generate ./... and subsequently using go build etc. the build should continue normally. Concerning the docs, a note to self, I'll add them - sorry for the inconvenience ;)

pojntfx avatar Oct 13 '20 08:10 pojntfx

follow your lead and try again, but I failed, emm, very confused, Not very good at golang. output below: kali@kali:~/go/src/github.com/pojntfx/gon2n/cmd/edged$ env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w" -o edged_x86.exe package github.com/pojntfx/gon2n/cmd/edged imports github.com/pojntfx/gon2n/pkg/workers: build constraints exclude all Go files in /home/kali/go/src/github.com/pojntfx/gon2n/pkg/workers

kali@kali:~/go/src/github.com/pojntfx/gon2n/cmd/supernoded$ env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w" -o supernoded_x86.exe package github.com/pojntfx/gon2n/cmd/supernoded imports github.com/pojntfx/gon2n/pkg/workers: build constraints exclude all Go files in /home/kali/go/src/github.com/pojntfx/gon2n/pkg/workers

Droid-MAX avatar Oct 13 '20 11:10 Droid-MAX

The build constraints error happens due to CGo; it is not possible to cross-compile CGo (n2n is written is C, so CGo is required). I do not test on Windows, but if you need to use that platform, I’d recommend either building on it directly using MinGW64 or using https://github.com/karalabe/xgo. If you want to I could also set up a Windows build workflow here in GitHub actions so you could just download the Windows binaries; right now, only macOS and Linux are supported.

pojntfx avatar Oct 14 '20 08:10 pojntfx

thanks. and I just release a asciinema cast about gon2n running on android: https://asciinema.org/a/365251 but it works lol

Droid-MAX avatar Oct 14 '20 11:10 Droid-MAX

I packaged gon2n into a standard debian package https://github.com/Droid-MAX/gon2n/releases

Droid-MAX avatar Oct 15 '20 11:10 Droid-MAX

That's awesome! I just noticed right now.

pojntfx avatar Feb 02 '21 16:02 pojntfx

Can We write a full manual document about static compiling GON2N?

Droid-MAX avatar Oct 13 '21 06:10 Droid-MAX

The key is that the Go Generate part component also needs static compilation.

Droid-MAX avatar Oct 13 '21 06:10 Droid-MAX

image

I try to compile gon2n on my zeropi board with armbian system but I got this error.

Droid-MAX avatar Oct 14 '21 07:10 Droid-MAX

@pojntfx Can you tell me the specific details of statically compiling gon2n?

Droid-MAX avatar Oct 19 '21 10:10 Droid-MAX

@Droid-MAX Sorry for not responding earlier, I've been busy with uni and work. I'll take a look at it later. Note that gon2n has to use CGo, so cross-compilation is harder.

pojntfx avatar Oct 22 '21 14:10 pojntfx

Note that static cross-compilation will probably not be possible. I'll be providing a workaround based on staticx though which will allow you to make the binaries "static" (by including & extracting the LDs). A preview: https://github.com/pojntfx/gon2n/tree/modernize-build-system (this should also make packaging for you much easier, as its a much more "standard" build system)

pojntfx avatar Oct 22 '21 15:10 pojntfx

Good news! Working on a custom gccgo cross-compiler, which now has reached a usable state and can compile gon2n: image

Note that all of this is Linux-only and will stay Linux-only though; I've checked n2n upstream too and as I've expected cross-compilation to Windows is also broken there. The clients and "esoteric" Linux platforms should work just fine though.

I'll be adding CI/CD to the cross-compiler etc. tomorrow.

pojntfx avatar Oct 24 '21 01:10 pojntfx

@Droid-MAX While I'm still working on a new release, you can already grab some static binaries for testing here: https://github.com/pojntfx/gon2n/releases/tag/unstable

pojntfx avatar Oct 24 '21 20:10 pojntfx

@Droid-MAX The release (v0.2.0) is out :) You can now just download the static binaries as described in the README or compile them from source; for instructions, check out https://github.com/pojntfx/gon2n#contributing, https://github.com/pojntfx/gon2n/blob/main/.github/workflows/hydrun.yaml and https://github.com/pojntfx/gon2n/blob/main/Hydrunfile.

pojntfx avatar Oct 24 '21 21:10 pojntfx

@pojntfx Can you use the strip command to reduce the file size?

Droid-MAX avatar Oct 25 '21 14:10 Droid-MAX

When using a 0.1.0 version I found that the specified encryption method will have an error when it is no encryption.

Droid-MAX avatar Oct 25 '21 14:10 Droid-MAX

The SuperNode parameter cannot use the domain name, and can only use the IP address, otherwise it will be wrong.

Droid-MAX avatar Oct 26 '21 02:10 Droid-MAX