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

Idea for making adding third party packages to Gomacro easier when plugins aren't available #143

Open
Keithcat1 opened this issue Feb 23, 2023 · 3 comments
Assignees

Comments

@Keithcat1
Copy link

The cleanest way I've thought of is for you to create a local Go package with only a main() function that just calls gomacro.main(), you use go get to add the third-party packages you want to import, and then you have Gomacro generate the import files as part of this package. This lets you control where the packages are coming from and should let you easily set up a template for building Gomacro with a bunch of popular Science packages and then other people can download and compile it with just a go get.

@Keithcat1
Copy link
Author

Currently what makes this hard is that gomacro --genimport doesn't let you dump the output in the current directory.

@cosmos72
Copy link
Owner

cosmos72 commented Jan 7, 2024

Background: current status

Gomacro uses the plugin package from standard library to import third-party packages at runtime.
As stated in https://pkg.go.dev/plugin "Plugins are currently supported only on Linux, FreeBSD, and macOS"

When running on other systems - for example Windows - the currently recommended workaround is to create an x_package.go file somewhere that collects all declarations from the package you want to import, add such file to gomacro sources, and recompile gomacro.

For that to work, you need a local writable copy of gomacro sources: go install github.com/cosmos72/gomacro@latest is not enough because it downloads gomacro sources into a somewhat hidden and usually read-only directory inside $GOPATH/go/pkg/mod/github.com/cosmos72/gomacro@...

Instead, you should download a copy of gomacro sources in $GOPATH/go/src/github.com/cosmos72/gomacro
then follow the instructions described at https://github.com/cosmos72/gomacro#other-systems

Basically you start gomacro and import "some/package/path" for each package you want to add.
For each such import, you will get a message like

// warning: created file "/home/user/go/src/github.com/cosmos72/gomacro/imports/thirdparty/some_package_path.go", recompile gomacro to use it

which means your local copy of gomacro sources have been modified, and should be recompiled.

Of course such solution is not go-gettable.

Proposed enhancement

If I understand correctly, what you are asking for is a simple method to generate an x_package.go file that collects all declarations for an arbitrary package X, and write it into inside an arbitrary package Y - or at least in the current directory.
In this way, you can manually add to package Y a Go function main() that registers the declarations for package X (or for multiple such packages) into gomacro, then starts gomacro itself.
And finally, you publish package Y somewhere, in order to allow users to go get it.

This is feasible, and it should be quite straightforward to implement, as the file x_package.go to create is similar enough to the one generated by import "some/package/path"

@cosmos72 cosmos72 self-assigned this Jan 7, 2024
@Keithcat1
Copy link
Author

Keithcat1 commented Jan 12, 2024

That's about it. Maybe add another command to the Gomacro CLI that generates a package adding the specified third-party packages to Gomacro, then you just go build it. This could be the default method to add third-party packages, it generally seems simpler and less hacky.

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

No branches or pull requests

2 participants