This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for go modules/plugins. (#29)
As we call the similar C binary a module I went with that name for the Go version as well. There's some trickery needed, Go does currently not support nocgo for modules, as noted in golang/go#30986 so that functionality has to be disabled. Also this triggers the CC environment variable problem again so I had to change the test CC value used.
- Loading branch information
Showing
15 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Go Dynamic Modules - GOMODULE | ||
|
||
GOMODULE(foo | ||
) | ||
|
||
Similar to [GOPROG](goprog.md) this uses go build to compile the directory into | ||
a binary. Unlike goprog, this descriptor creates a dynamic loadable module | ||
instead of a runnable progam. By default the module is created in the | ||
`modules/` [destination directory](../arguments/destdir.md) and will have a | ||
`.so` file suffix. | ||
|
||
In the Go echosystem, these are known as plugins and you use the standard | ||
[plugin](https://godoc.org/plugin) package to load them. | ||
|
||
GOMODULE support most the same arguments as GOPROG does, so refer to | ||
[GOPROG arguments](goprog.md#arguments) for descriptions of additional | ||
arguments. Special conditions and ninja variables are described on that | ||
page as well. Since Go doesn't support compiling these modules without | ||
cgo the `nocgo` argument is not available. Other settings disabling cgo | ||
are also ignored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
COMPONENT([ | ||
goarch | ||
go/src/gopath | ||
gomodules/loader | ||
gomodules/module | ||
collect_special | ||
srcdir | ||
c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GOPROG(loader | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"plugin" | ||
) | ||
|
||
func main() { | ||
for _, pstr := range os.Args[1:] { | ||
p, err := plugin.Open(pstr) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
test, err := p.Lookup("Test") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println(test.(func() string)()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GOMODULE(gomod | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net" | ||
"strings" | ||
) | ||
|
||
func Test() string { | ||
// Use the net package to try to explicitly use cgo | ||
addrs, err := net.DefaultResolver.LookupHost(context.Background(), "localhost") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return strings.Join(addrs, ", ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters