Comments (2)
Update: import ( ... )
now compiles and imports multiple packages using a single Go plugin - which helps solving dependency versions conflicts.
We are getting nearer, but the imports above do not work yet. The following happens on Linux/amd64:
gomacro> import (
"fmt"
"github.com/switchupcb/copygen/cli/generator" // third party module; not reflected
"github.com/switchupcb/copygen/cli/models" // extracted module
)
// debug: running "go get github.com/switchupcb/copygen/cli/generator github.com/switchupcb/copygen/cli/models" ...
go: downloading github.com/switchupcb/copygen v0.3.7
go: downloading golang.org/x/tools v0.1.10
go: downloading github.com/switchupcb/yaegi v0.10.2
go: downloading golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
go: downloading golang.org/x/sys v0.0.0-20220422013727-9388b58f7150
go: downloading golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f
go: added github.com/switchupcb/copygen v0.3.7
go: added github.com/switchupcb/yaegi v0.10.2
go: added golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
go: added golang.org/x/sys v0.0.0-20220422013727-9388b58f7150
go: added golang.org/x/tools v0.1.10
go: added golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f
// debug: running "go mod tidy" ...
// debug: compiling plugin "/home/max/go/src/gomacro.imports/gomacro_pid_89600/import_1" ...
error loading plugin "/home/max/go/src/gomacro.imports/gomacro_pid_89600/import_1/import_1.so": plugin.Open("/home/max/go/src/gomacro.imports/gomacro_pid_89600/import_1/import_1"): plugin was built with a different version of package golang.org/x/sys/execabs
from gomacro.
Hello @switchupcb,
gomacro supports importing third-party packages without recompilation only on Linux and Mac OS X, because it compiles them as a shared library then loads the shared library with Go function plugin.Open()
which is currently only available on those two operating systems - as far as I know, nobody implemented it yet on Windows.
For your specific case, I tried executing
import (
"fmt"
"github.com/switchupcb/copygen/cli/generator" // third party module; not reflected
"github.com/switchupcb/copygen/cli/models" // extracted module
)
inside gomacro running on Linux/arm64 (inside UserLand on my Android mobile) and it produced some errors:
// debug: running "go get github.com/switchupcb/copygen/cli/generator" ...
go: downloading github.com/switchupcb/copygen v0.2.4
go: downloading github.com/switchupcb/yaegi v0.10.2
go: downloading golang.org/x/tools v0.1.6
go: downloading golang.org/x/sys v0.0.0-20210927052749-1cf2251ac284
go: added github.com/switchupcb/copygen v0.2.4
go: added github.com/switchupcb/yaegi v0.10.2
go: added golang.org/x/mod v0.5.1
go: added golang.org/x/sys v0.0.0-20210927052749-1cf2251ac284
go: added golang.org/x/tools v0.1.6
go: added golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
// debug: running "go mod tidy" ...
// debug: compiling "/home/max/go/src/gomacro.imports/github.com/switchupcb/copygen/cli/generator/generator.go" ...
# golang.org/x/tools/internal/typeparams
/home/max/go/pkg/mod/golang.org/x/[email protected]/internal/typeparams/typeparams_go118.go:78:6: sig.SetTypeParams undefined (type *types.Signature has no field or method SetTypeParams)
/home/max/go/pkg/mod/golang.org/x/[email protected]/internal/typeparams/typeparams_go118.go:88:6: sig.SetRecvTypeParams undefined (type *types.Signature has no field or method SetRecvTypeParams)
/home/max/go/pkg/mod/golang.org/x/[email protected]/internal/typeparams/typeparams_go118.go:98:15: iface.IsConstraint undefined (type *types.Interface has no field or method IsConstraint)
/home/max/go/pkg/mod/golang.org/x/[email protected]/internal/typeparams/typeparams_go118.go:144:7: info.Inferred undefined (type *types.Info has no field or method Inferred)
// more errors...
I will have a look if it works better on a PC (i.e. Linux/amd4).
About using gomacro inside gomacro: there are at least three different ways to do that.
-
Using some kind of
eval()
function to interpret arbitrary source code. This is supported natively: from gomacro prompt (or equivalently, when starting gomacro as a library from compiled code) you can use theEval()
function. -
You can
import "github.com/cosmos72/gomacro/fast"
from interpreted code to load and instantiate another interpreter, and interact with it: send code to be executed to it, etc. -
Interpret the interpreter: if you try to load gomacro source code inside another gomacro interpreter and run them (i.e. interpreting the interpreter) they will not work for several reasons - the main one is that gomacro relies on
unsafe.Pointer
in someplaces, but does not implement it: interpreted code cannot* currently useunsafe.Pointer
.
from gomacro.
Related Issues (20)
- I would like a full working example how to inject my application context(types and functions) in the REPL HOT 9
- Extract struct with methods from script to compiled code HOT 2
- Proxy can mix the called method of the imported structure HOT 3
- integrate with https://github.com/go-rod/rod HOT 2
- I'm unable to compile code importing gomacro on Mac OS m1 pro HOT 7
- Is there a way to Eval a folder HOT 5
- recursive type error cases: call of reflect.Value.Interface on zero Value HOT 6
- can't import fsm package HOT 4
- Different compilation behaviour from native go HOT 2
- undefined: pkgpath HOT 3
- Cannot convert struct to interface if it has an embedded struct with a method HOT 4
- Cannot import third party packages on Linux (not even the ones in the README) HOT 2
- Third-party imported type method is not callable from fast.Interp.Eval [gomacro repl works] HOT 4
- Idea for making adding third party packages to Gomacro easier when plugins aren't available HOT 3
- recursive type error cases: call of reflect.Value.Interface on zero Value
- can not import 3rd party packages HOT 13
- package <package> exports zero constants, functions, types, and variables HOT 3
- Caching of interp.Eval1 results HOT 13
- Way to disable go get import and enforce to use only defined import list HOT 3
- An error will be reported when using third-party packages on Windows HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomacro.