I’m not sure what’s the essense of the question. IP_TRANSPARENT
is specific to Linux (an OS kernel), so any code which makes use of it must run on Linux. Debugging (a running process) also must happen on Linux—for, I hope, reasons now obvious.
But that does not affect building: when building on Linux, that should work if your version of Go has IP_TRANSPARENT
defined in its syscall
package.
This means:
- Running the program built for
linux/amd64
making use ofsyscall.IP_TRANSPARENT
on the VM with a Linux guest should work. - Building that program from the source code on the VM with a Linux guest should work.
But “plain” building on a non-native platform (which is darwin/arm64
in our case, if I understand correctly) will not work, and this might be the source of your confusion.
Basically, when you’re building the source code on darwin/arm64
, the compiler locates, reads and interprets all the sources expecting to produce an executable image file suitable for the platform it’s working on; the syscall
package, being highly OS-dependent, can be though of as being different for different GOOS/GOARCH
combos.
Its “version” for darwin/arm64
simply cannot contain the symbol IP_TRANSPARENT
because the darwin kernel does not “know” about it.
So, if your issue is merely building for linux/amd64
while working on darwin/arm64
, the answer is cross-compilation.
With Go, it’s done by making the toolchain see explicit settings for the GOOS
and/or GOARCH
environment variables—different from the assumed defaults.
In your case you could just do
$ GOOS=linux GOARCH=amd64 go build
and it will produce an executable image file ready for linux/amd64
, and when processing the source code, the compiler will use the definitions for the target platform, not the platform it’s running on.
You can then copy (or make availabe by other means) the produced executable image file to the guest’s filesystem and run it there—it should work just fine.
You can make such changes “permanent” for the current Termial session by doing
$ export GOOS=linux
$ export GOARCH=amd64
TL;DR
- To build for a non-native platform, use cross-compiling; you do not need any sort of VM.
- Or you can build “natively” but then you need to install
go
into the guest running on a VM, and make the project’s source code available there. - To run an executable for a non-native system you must use a VM (or some sort of emulator).
0
solved Is there any way to run an amd64/linux VM on Apple Silicon M? [closed]