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
Cannot import packages that export C symbols #77
Comments
Glad you're looking into this. Is this relatively easy to implement? |
Probably there is a simpler solution (to be tested): execute one of the commands This has a non-zero chance to work because |
I tried: I think I mensioned this, but it works if I use :options Import.Uses.Module before importing the package that requires C. You could always rip the code from CGO and use that to get the required info. |
I'm also glad you are looking into this @cosmos72. The Gomacro REPL is already very useful and it's quite a pleasure to use. Being able to import packages that export C symbols would be a valuable addition to the use-cases for when Gomacro may be used. |
The reason is:
to download and scan packages, gomacro uses
golang.org/x/tools/go/packages
- which is unable to compute the type of C symbols and the value of C constants (for good reasons: you need a C compiler for that).Thus
golang.org/x/tools/go/packages
returns an error when trying to create the metadata of a package that exports C symbols, gomacro receives that error and bails out.There is a possibile solution: to generate an import file, gomacro only needs the names of exported symbols, not their types or values (actually, knowing the exact values of untyped constants and the methods of interfaces would be useful too, but not absolutely required).
So, if
golang.org/x/tools/go/packages
successfully downloads a package, but fails to create its metadata, gomacro could locate the relevant sources inside $GOPATH/pkg/mod, parse them, collect the names of exported symbols, generate a (slightly reduced) import file and compile and load it normally as a plugin.The text was updated successfully, but these errors were encountered: