Switch remote deploy to vendored source builds
Move remote deployment to a vendored source bundle built on the target host via Docker so redeploys no longer require local cross-compilation or host Go installation. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
239
vendor/github.com/wailsapp/go-webview2/pkg/combridge/bridge.go
generated
vendored
Normal file
239
vendor/github.com/wailsapp/go-webview2/pkg/combridge/bridge.go
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
//go:build windows
|
||||
|
||||
package combridge
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
var (
|
||||
comIfcePointersL sync.RWMutex
|
||||
comIfcePointers = map[uintptr]*comObject{} // Map from ComInterfacePointer to the Go ComObject
|
||||
)
|
||||
|
||||
// Resolve the GoInterface of the specified ComInterfacePointer
|
||||
func Resolve[T IUnknown](ifceP uintptr) T {
|
||||
comIfcePointersL.RLock()
|
||||
comObj := comIfcePointers[ifceP]
|
||||
comIfcePointersL.RUnlock()
|
||||
|
||||
var n T
|
||||
if comObj != nil {
|
||||
t := comObj.resolve(ifceP)
|
||||
if t != nil {
|
||||
n = t.(T)
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// New returns a new ComObject which implements the specified Com Interface, com calls will be redirected
|
||||
// to the specified go interface.
|
||||
func New[T IUnknown](obj T) *ComObject[T] {
|
||||
cObj := new(
|
||||
ifceDef[T]{obj},
|
||||
)
|
||||
return newComObject[T](cObj)
|
||||
}
|
||||
|
||||
// New2 returns a new ComObject which implements the two specified Com Interfaces, com calls will be redirected
|
||||
// to those interfaces accordingly.
|
||||
// This is needed if a ComObject should implement two interfaces that are not descendants of each other,
|
||||
// then you get multiple inheritance.
|
||||
func New2[T IUnknown, T2 IUnknown](obj T, obj2 T2) *ComObject[T] {
|
||||
cObj := new(
|
||||
ifceDef[T]{obj},
|
||||
ifceDef[T2]{obj2},
|
||||
)
|
||||
return newComObject[T](cObj)
|
||||
}
|
||||
|
||||
// new returns a new ComObject which implements multiple specified Com Interfaces, com calls will be redirected
|
||||
// to the specified go interfaces accordingly.
|
||||
// This is needed if a ComObject should implement multiple interfaces that are not descendants of each other,
|
||||
// then you get multiple inheritance.
|
||||
func new(impls ...ifceImpl) *comObject {
|
||||
impls = append([]ifceImpl{ifceDef[IUnknown]{}}, impls...)
|
||||
|
||||
cObj := &comObject{
|
||||
refCount: 1,
|
||||
ifces: map[string]int{},
|
||||
ifcesImpl: make([]comInterfaceDesc, len(impls)),
|
||||
}
|
||||
|
||||
for i, ifceDef := range impls {
|
||||
vtable, err := ifceDef.ifce()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
needsImplement := false
|
||||
for table := vtable; table != nil; table = table.Parent {
|
||||
guid := table.ComGUID
|
||||
if i, found := cObj.ifces[guid]; found {
|
||||
// This Interface is already implemented
|
||||
if guid == iUnknownGUID {
|
||||
// IUnknown is a special interface and never has an user specific implementation
|
||||
} else if cObj.ifcesImpl[i].impl != ifceDef.impl() {
|
||||
panic(fmt.Sprintf("Interface '%s' is already implemented by another object", table.Name))
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
needsImplement = true
|
||||
cObj.ifces[guid] = i
|
||||
}
|
||||
|
||||
if !needsImplement {
|
||||
continue
|
||||
}
|
||||
|
||||
ifceP, ifcePSlice := allocUintptrObject(1)
|
||||
ifcePSlice[0] = vtable.ComVTable
|
||||
cObj.ifcesImpl[i] = comInterfaceDesc{ifceP, ifceDef.impl()}
|
||||
}
|
||||
|
||||
comIfcePointersL.Lock()
|
||||
for _, ifceImpl := range cObj.ifcesImpl {
|
||||
comIfcePointers[ifceImpl.ref] = cObj
|
||||
}
|
||||
comIfcePointersL.Unlock()
|
||||
|
||||
return cObj
|
||||
}
|
||||
|
||||
func newComObject[T IUnknown](comObj *comObject) *ComObject[T] {
|
||||
c := &ComObject[T]{obj: comObj}
|
||||
// Make sure to async release since release needs locks and might block the finalizer goroutine for a longer period
|
||||
runtime.SetFinalizer(c, func(obj *ComObject[T]) { obj.close(true) })
|
||||
return c
|
||||
}
|
||||
|
||||
// ComObject describes an exported go instance to be used as a ComObject which implements
|
||||
// the specified Interface.
|
||||
type ComObject[T IUnknown] struct {
|
||||
obj *comObject
|
||||
closed int32
|
||||
}
|
||||
|
||||
// Ref returns the native uintptr that points to the ComObject that is an interface pointer to T.
|
||||
// This can be used in native calls. If the object has been closed this function will panic.
|
||||
func (o *ComObject[T]) Ref() uintptr {
|
||||
if atomic.LoadInt32(&o.closed) != 0 {
|
||||
panic("ComObject has been released")
|
||||
}
|
||||
return o.obj.queryInterface(guidOf[T](), false)
|
||||
}
|
||||
|
||||
// Close releases the native com object from the go side. It will only be destroyed if the ref counter
|
||||
// reaches zero.
|
||||
// After closing `Ref()` will panic.
|
||||
func (o *ComObject[T]) Close() error {
|
||||
o.close(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
// close releases the native com object from the go side. It will only be destroyed if the ref counter
|
||||
// reaches zero.
|
||||
// After closing `Ref()` will panic.
|
||||
func (o *ComObject[T]) close(asyncRelease bool) {
|
||||
if atomic.CompareAndSwapInt32(&o.closed, 0, 1) {
|
||||
runtime.SetFinalizer(o, nil)
|
||||
if asyncRelease {
|
||||
go o.obj.release()
|
||||
} else {
|
||||
o.obj.release()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type comInterfaceDesc struct {
|
||||
ref uintptr // The native Com InterfacePointer
|
||||
impl any // The golang target object
|
||||
}
|
||||
|
||||
type comObject struct {
|
||||
l sync.Mutex
|
||||
|
||||
refCount int32
|
||||
ifces map[string]int // Map of ComInterfaceGUID to Interface Slots
|
||||
ifcesImpl []comInterfaceDesc // Slots with InterfaceDescriptors
|
||||
}
|
||||
|
||||
func (c *comObject) queryInterface(ifceGUID string, withAddRef bool) uintptr {
|
||||
c.l.Lock()
|
||||
defer c.l.Unlock()
|
||||
if c.refCount <= 0 {
|
||||
panic("call on released com object")
|
||||
}
|
||||
|
||||
i, found := c.ifces[ifceGUID]
|
||||
if !found {
|
||||
return 0
|
||||
}
|
||||
|
||||
if withAddRef {
|
||||
c.refCount++
|
||||
}
|
||||
return c.ifcesImpl[i].ref
|
||||
}
|
||||
|
||||
func (c *comObject) resolve(ifceP uintptr) any {
|
||||
c.l.Lock()
|
||||
defer c.l.Unlock()
|
||||
if c.refCount <= 0 {
|
||||
panic("call on destroyed com object")
|
||||
}
|
||||
|
||||
for _, ifce := range c.ifcesImpl {
|
||||
if ifce.ref != ifceP {
|
||||
continue
|
||||
}
|
||||
|
||||
return ifce.impl
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *comObject) addRef() int32 {
|
||||
c.l.Lock()
|
||||
defer c.l.Unlock()
|
||||
if c.refCount <= 0 {
|
||||
panic("call on destroyed com object")
|
||||
}
|
||||
|
||||
c.refCount++
|
||||
return c.refCount
|
||||
}
|
||||
|
||||
func (c *comObject) release() int32 {
|
||||
c.l.Lock()
|
||||
defer c.l.Unlock()
|
||||
if c.refCount <= 0 {
|
||||
panic("call on destroyed com object")
|
||||
}
|
||||
|
||||
if c.refCount--; c.refCount == 0 {
|
||||
comIfcePointersL.Lock()
|
||||
for _, ref := range c.ifcesImpl {
|
||||
delete(comIfcePointers, ref.ref)
|
||||
}
|
||||
comIfcePointersL.Unlock()
|
||||
|
||||
for _, impl := range c.ifcesImpl {
|
||||
ref := impl.ref
|
||||
if ref == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
globalFree(ref)
|
||||
}
|
||||
}
|
||||
|
||||
return c.refCount
|
||||
}
|
||||
56
vendor/github.com/wailsapp/go-webview2/pkg/combridge/iunknown.go
generated
vendored
Normal file
56
vendor/github.com/wailsapp/go-webview2/pkg/combridge/iunknown.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
//go:build windows
|
||||
|
||||
package combridge
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
const iUnknownGUID = "{00000000-0000-0000-C000-000000000046}"
|
||||
|
||||
func init() {
|
||||
registerVTableInternal[IUnknown, IUnknown](
|
||||
iUnknownGUID,
|
||||
true,
|
||||
iUnknownQueryInterface,
|
||||
iUnknownAddRef,
|
||||
iUnknownRelease,
|
||||
)
|
||||
}
|
||||
|
||||
type IUnknown interface{}
|
||||
|
||||
func iUnknownQueryInterface(this uintptr, refiid *windows.GUID, ppvObject *uintptr) uintptr {
|
||||
if refiid == nil || ppvObject == nil {
|
||||
return uintptr(windows.E_INVALIDARG)
|
||||
}
|
||||
|
||||
comIfcePointersL.RLock()
|
||||
obj := comIfcePointers[this]
|
||||
comIfcePointersL.RUnlock()
|
||||
|
||||
ref := obj.queryInterface(refiid.String(), true)
|
||||
if ref != 0 {
|
||||
*ppvObject = ref
|
||||
return windows.NO_ERROR
|
||||
}
|
||||
|
||||
*ppvObject = 0
|
||||
return uintptr(windows.E_NOINTERFACE)
|
||||
}
|
||||
|
||||
func iUnknownAddRef(this uintptr) uintptr {
|
||||
comIfcePointersL.RLock()
|
||||
obj := comIfcePointers[this]
|
||||
comIfcePointersL.RUnlock()
|
||||
|
||||
return uintptr(obj.addRef())
|
||||
}
|
||||
|
||||
func iUnknownRelease(this uintptr) uintptr {
|
||||
comIfcePointersL.RLock()
|
||||
obj := comIfcePointers[this]
|
||||
comIfcePointersL.RUnlock()
|
||||
|
||||
return uintptr(obj.release())
|
||||
}
|
||||
74
vendor/github.com/wailsapp/go-webview2/pkg/combridge/iunknown_impl.go
generated
vendored
Normal file
74
vendor/github.com/wailsapp/go-webview2/pkg/combridge/iunknown_impl.go
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
//go:build windows
|
||||
|
||||
package combridge
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// IUnknownFromPointer cast a generic pointer into a IUnknownImpl pointer
|
||||
func IUnknownFromPointer(ref unsafe.Pointer) *IUnknownImpl {
|
||||
return (*IUnknownImpl)(ref)
|
||||
}
|
||||
|
||||
// IUnknownFromPointer cast native pointer into a IUnknownImpl pointer
|
||||
func IUnknownFromUintptr(ref uintptr) *IUnknownImpl {
|
||||
return IUnknownFromPointer(unsafe.Pointer(ref))
|
||||
}
|
||||
|
||||
type IUnknownVtbl struct {
|
||||
queryInterface uintptr
|
||||
addRef uintptr
|
||||
release uintptr
|
||||
}
|
||||
|
||||
func (i *IUnknownVtbl) QueryInterface(this unsafe.Pointer, refiid *windows.GUID, ppvObject **IUnknownImpl) error {
|
||||
r, _, _ := syscall.SyscallN(
|
||||
i.queryInterface,
|
||||
uintptr(this),
|
||||
uintptr(unsafe.Pointer(refiid)),
|
||||
uintptr(unsafe.Pointer(ppvObject)),
|
||||
)
|
||||
|
||||
if r != uintptr(windows.S_OK) {
|
||||
return syscall.Errno(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *IUnknownVtbl) AddRef(this unsafe.Pointer) uint32 {
|
||||
r, _, _ := syscall.SyscallN(
|
||||
i.addRef,
|
||||
uintptr(this),
|
||||
)
|
||||
return uint32(r)
|
||||
}
|
||||
|
||||
func (i *IUnknownVtbl) Release(this unsafe.Pointer) uint32 {
|
||||
r, _, _ := syscall.SyscallN(
|
||||
i.release,
|
||||
uintptr(this),
|
||||
)
|
||||
|
||||
return uint32(r)
|
||||
}
|
||||
|
||||
type IUnknownImpl struct {
|
||||
vtbl *IUnknownVtbl
|
||||
}
|
||||
|
||||
func (i *IUnknownImpl) QueryInterface(refiid *windows.GUID, ppvObject **IUnknownImpl) error {
|
||||
return i.vtbl.QueryInterface(unsafe.Pointer(i), refiid, ppvObject)
|
||||
}
|
||||
|
||||
func (i *IUnknownImpl) AddRef() uint32 {
|
||||
return i.vtbl.AddRef(unsafe.Pointer(i))
|
||||
}
|
||||
|
||||
func (i *IUnknownImpl) Release() uint32 {
|
||||
return i.vtbl.Release(unsafe.Pointer(i))
|
||||
}
|
||||
39
vendor/github.com/wailsapp/go-webview2/pkg/combridge/syscall.go
generated
vendored
Normal file
39
vendor/github.com/wailsapp/go-webview2/pkg/combridge/syscall.go
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
//go:build windows
|
||||
|
||||
package combridge
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
procGlobalAlloc = modkernel32.NewProc("GlobalAlloc")
|
||||
procGlobalFree = modkernel32.NewProc("GlobalFree")
|
||||
|
||||
uintptrSize = unsafe.Sizeof(uintptr(0))
|
||||
)
|
||||
|
||||
func allocUintptrObject(size int) (uintptr, []uintptr) {
|
||||
v := globalAlloc(uintptr(size) * uintptrSize)
|
||||
slice := unsafe.Slice((*uintptr)(unsafe.Pointer(v)), size)
|
||||
return v, slice
|
||||
}
|
||||
|
||||
func globalAlloc(dwBytes uintptr) uintptr {
|
||||
ret, _, _ := procGlobalAlloc.Call(uintptr(0), dwBytes)
|
||||
if ret == 0 {
|
||||
panic("globalAlloc failed")
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func globalFree(data uintptr) {
|
||||
ret, _, _ := procGlobalFree.Call(data)
|
||||
if ret != 0 {
|
||||
panic("globalFree failed")
|
||||
}
|
||||
}
|
||||
147
vendor/github.com/wailsapp/go-webview2/pkg/combridge/vtables.go
generated
vendored
Normal file
147
vendor/github.com/wailsapp/go-webview2/pkg/combridge/vtables.go
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
//go:build windows
|
||||
|
||||
package combridge
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
vTablesL sync.Mutex
|
||||
vTables = make(map[string]*vTable)
|
||||
)
|
||||
|
||||
// RegisterVTable registers the vtable trampoline methods for the specified ComInterface
|
||||
// TBase is the base interface of T, and must be another ComInterface which roots in IUnknown or IUnknown itself.
|
||||
// The first paramter of the fn is always the uintptr of the ComObject and the GoObject can be resolved with Resolve().
|
||||
// After having resolved the GoObject the call must be redirected to the GoObject.
|
||||
// Typically a trampoline FN looks like this.
|
||||
//
|
||||
// func _ICoreWebView2NavigationCompletedEventHandlerInvoke(this uintptr, sender *ICoreWebView2, args *ICoreWebView2NavigationCompletedEventArgs) uintptr {
|
||||
// return combridge.Resolve[_ICoreWebView2NavigationCompletedEventHandler](this).NavigationCompleted(sender, args)
|
||||
// }
|
||||
//
|
||||
// The order of registration must be in the correct order as specified in the IDL of the interface.
|
||||
func RegisterVTable[TParent, T IUnknown](guid string, fns ...interface{}) {
|
||||
registerVTableInternal[TParent, T](guid, false, fns...)
|
||||
}
|
||||
|
||||
type vTable struct {
|
||||
Parent *vTable
|
||||
|
||||
Name string
|
||||
ComGUID string
|
||||
ComVTable uintptr
|
||||
ComProcs []uintptr
|
||||
}
|
||||
|
||||
func registerVTableInternal[TParent, T IUnknown](guid string, isInternal bool, fns ...interface{}) {
|
||||
vTablesL.Lock()
|
||||
defer vTablesL.Unlock()
|
||||
|
||||
t, tName := typeInterfaceToString[T]()
|
||||
tParent, tParentName := typeInterfaceToString[TParent]()
|
||||
if !t.Implements(tParent) {
|
||||
panic(fmt.Errorf("RegisterVTable '%s': '%s' must implement '%s'", tName, tName, tParentName))
|
||||
}
|
||||
|
||||
if !isInternal {
|
||||
if t == reflect.TypeOf((*IUnknown)(nil)).Elem() {
|
||||
panic(fmt.Errorf("RegisterVTable '%s' IUnknown can't be registered", tName))
|
||||
}
|
||||
|
||||
if t == tParent {
|
||||
panic(fmt.Errorf("RegisterVTable '%s': T and TParent can't be the same type", tName))
|
||||
}
|
||||
}
|
||||
|
||||
var parent *vTable
|
||||
var parentProcs []uintptr
|
||||
var parentProcsCount int
|
||||
if t != tParent {
|
||||
parent = vTables[tParentName]
|
||||
if parent == nil {
|
||||
panic(fmt.Errorf("RegisterVTable '%s': Parent VTable '%s' not registered", tName, tParentName))
|
||||
}
|
||||
|
||||
parentProcs = parent.ComProcs
|
||||
parentProcsCount = len(parentProcs)
|
||||
}
|
||||
|
||||
comGuid, err := windows.GUIDFromString(guid)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("RegisterVTable '%s': invalid guid: %s", tName, err))
|
||||
}
|
||||
|
||||
vTable := &vTable{
|
||||
Parent: parent,
|
||||
Name: tName,
|
||||
ComGUID: comGuid.String(),
|
||||
}
|
||||
vTable.ComVTable, vTable.ComProcs = allocUintptrObject(parentProcsCount + len(fns))
|
||||
|
||||
for i, proc := range parentProcs {
|
||||
vTable.ComProcs[i] = proc
|
||||
}
|
||||
|
||||
for i, fn := range fns {
|
||||
vTable.ComProcs[parentProcsCount+i] = windows.NewCallback(fn)
|
||||
}
|
||||
|
||||
vTables[tName] = vTable
|
||||
}
|
||||
|
||||
func typeInterfaceToString[T any]() (reflect.Type, string) {
|
||||
t := reflect.TypeOf((*T)(nil))
|
||||
if t.Kind() != reflect.Pointer {
|
||||
panic("must be a (*yourInterfaceType)(nil)")
|
||||
}
|
||||
t = t.Elem()
|
||||
return t, t.PkgPath() + "/" + t.Name()
|
||||
}
|
||||
|
||||
func typeInterfaceToStringOnly[T any]() string {
|
||||
_, nane := typeInterfaceToString[T]()
|
||||
return nane
|
||||
}
|
||||
|
||||
func guidOf[T any]() string {
|
||||
vtable := vTableOf[T]()
|
||||
if vtable == nil {
|
||||
return ""
|
||||
}
|
||||
return vtable.ComGUID
|
||||
}
|
||||
|
||||
func vTableOf[T any]() *vTable {
|
||||
name := typeInterfaceToStringOnly[T]()
|
||||
vTablesL.Lock()
|
||||
defer vTablesL.Unlock()
|
||||
|
||||
return vTables[name]
|
||||
}
|
||||
|
||||
type ifceImpl interface {
|
||||
impl() any
|
||||
ifce() (*vTable, error)
|
||||
}
|
||||
|
||||
type ifceDef[T any] struct {
|
||||
objImpl any
|
||||
}
|
||||
|
||||
func (i ifceDef[T]) impl() any {
|
||||
return i.objImpl
|
||||
}
|
||||
|
||||
func (i ifceDef[T]) ifce() (*vTable, error) {
|
||||
vtable := vTableOf[T]()
|
||||
if vtable == nil {
|
||||
return nil, fmt.Errorf("Unable to find vTable for %s", typeInterfaceToStringOnly[T]())
|
||||
}
|
||||
return vtable, nil
|
||||
}
|
||||
Reference in New Issue
Block a user