inkeliz / gowebview

Simple WebView for Golang, avoiding CGO for Windows.
MIT License
54 stars 12 forks source link

darwin #1

Closed gedw99 closed 3 years ago

gedw99 commented 4 years ago

i know darwin is not supported. not needing CGO is a great idea.

It is probably only a matter of looking into the right system calls.

but here is the error


go build -o ./example .
# github.com/inkeliz/gowebview
Undefined symbols for architecture x86_64:
  "_webview_create", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_create in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_create)
  "_webview_destroy", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_destroy in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_destroy)
  "_webview_eval", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_eval in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_eval)
  "_webview_get_window", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_get_window in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_get_window)
  "_webview_init", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_init in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_init)
  "_webview_navigate", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_navigate in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_navigate)
  "_webview_run", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_run in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_run)
  "_webview_set_size", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_set_size in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_set_size)
  "_webview_set_title", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_set_title in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_set_title)
  "_webview_terminate", referenced from:
      __cgo_fb6f7ea8c7eb_Cfunc_webview_terminate in _x002.o
     (maybe you meant: __cgo_fb6f7ea8c7eb_Cfunc_webview_terminate)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build] Error 2
gedw99 commented 4 years ago

Ok i get how the archi works https://github.com/Inkeliz/gowebview/blob/master/generator/generate.go

is this a comöiled version of https://github.com/webview/webview that is embedded ?

inkeliz commented 4 years ago

Well, for Darwin/Linux it still needs CGO (and the .dylib/.so must be in the same folder): just as the regular webview/webview. It's a slightly modified version of https://github.com/webview/webview. I adapt to conform to the new WebView interface.


The generator.go creates the lib_*.go files (such as https://github.com/Inkeliz/gowebview/blob/master/lib_window.go). All those files (only used by Windows at webview_windows.go) are extracted when you run the New() function:

https://github.com/Inkeliz/gowebview/blob/3d75c1d755e6170a77458ac1c44904f5aac3c3ba/webview_windows.go#L41-L49

That makes it possible to load the DLL. The DDL is loaded after the execution, using LazyLoad:

https://github.com/Inkeliz/gowebview/blob/3d75c1d755e6170a77458ac1c44904f5aac3c3ba/webview_windows.go#L57-L60

That is the trick to avoid CGO and to make possible to extract the DLL.

It's not possible to do that on the webview/webview, since Golang looks for the DLL at the startup of the software, so you can't execute anything because it crashes. That was the only reason to create that new library.

That changes is only applied to Windows, others plataforms remains unchanged.


About the lib folder, it has all .dll/.dylib/.so, and you can get from https://github.com/webview/webview_csharp/tree/master/libs. It's only used by go generate to create lib_*.go files.

In that case, copy the libwebview.dylib and paste that file in the same folder of the executable. It may works since it's the same of webview/webview (it uses CGO).


Android is my priority for now. Of course, it will use CGO (since it's using JNI), but it's what I need for now. I may remove the Darwin/Linux stuff altogether or change to make it work with CGO, and I don't know. For now, I'm ignoring Darwin/Linux. :\

inkeliz commented 3 years ago

I think forking will be the best solution. (:

I finally get the Android version to work, at least the basic stuff (loading pages, almost). However, gomobile build nor go build works, since it needs some Java to be glued together. However, to abstract all java stuff: I'm creating one executable that runs as gowebview build (instead of go build), so you get the .apk quickly. I expect to release at the end of that week.