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

Support building on 32-bit platforms #115

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions cmd/genbindings/emitgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"fmt"
"go/format"
"log"
"math"
"path"
"sort"
"strconv"
"strings"
)

Expand Down Expand Up @@ -643,7 +645,7 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue

}

func emitGo(src *CppParsedHeader, headerName string, packageName string) (string, error) {
func emitGo(src *CppParsedHeader, headerName string, packageName string) (string, string, error) {

ret := strings.Builder{}
ret.WriteString(`package ` + path.Base(packageName) + `
Expand All @@ -664,6 +666,8 @@ import "C"
currentPackageName: packageName,
}

var bigints []string

// Check if short-named enums are allowed.
// We only allow short names if there are no conflicts anywhere in the whole
// file. This doesn't fully defend against cross-file conflicts but those
Expand Down Expand Up @@ -716,13 +720,41 @@ import "C"

if len(e.Entries) > 0 {

ret.WriteString("const (\n")
var smallvalues []string

for _, ee := range e.Entries {
ret.WriteString(titleCase(cabiClassName(goEnumShortName+"::"+ee.EntryName)) + " " + goEnumName + " = " + ee.EntryValue + "\n")

isBigInt := false

if e.UnderlyingType.IntType() {
// Int-type enums need special handling in case of 64-bit
// overflow, that would prevent using miqt on 32-bit platforms

entryValueI64, err := strconv.ParseInt(ee.EntryValue, 10, 64)
if err != nil {
panic("Enum " + ee.EntryName + " has non-parseable integer value")
}

if entryValueI64 > math.MaxInt32 || entryValueI64 < math.MinInt32 {
isBigInt = true
}
}

enumConstDeclaration := titleCase(cabiClassName(goEnumShortName+"::"+ee.EntryName)) + " " + goEnumName + " = " + ee.EntryValue

if isBigInt {
bigints = append(bigints, "const "+enumConstDeclaration+"\n")
} else {
smallvalues = append(smallvalues, enumConstDeclaration+"\n")
}
}

if len(smallvalues) > 0 {
ret.WriteString("const (\n")
ret.WriteString(strings.Join(smallvalues, ""))
ret.WriteString("\n)\n\n")
}

ret.WriteString("\n)\n\n")
}
}

Expand Down Expand Up @@ -1085,5 +1117,14 @@ import "C"
formattedSrc = []byte(goSrc)
}

return string(formattedSrc), nil
// Determine if we need to produce a _64bit.go file
bigintSrc := ""
if len(bigints) > 0 {
bigintSrc = `//go:build !386 && !arm
// +build !386,!arm

package ` + path.Base(packageName) + "\n\n" + strings.Join(bigints, "") + "\n"
}

return string(formattedSrc), bigintSrc, nil
}
9 changes: 8 additions & 1 deletion cmd/genbindings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b
counter++
}

goSrc, err := emitGo(parsed, filepath.Base(parsed.Filename), packageName)
goSrc, go64Src, err := emitGo(parsed, filepath.Base(parsed.Filename), packageName)
if err != nil {
panic(err)
}
Expand All @@ -232,6 +232,13 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b
panic(err)
}

if len(go64Src) > 0 {
err = os.WriteFile(outputName+"_64bit.go", []byte(go64Src), 0644)
if err != nil {
panic(err)
}
}

bindingCppSrc, err := emitBindingCpp(parsed, filepath.Base(parsed.Filename))
if err != nil {
panic(err)
Expand Down
22 changes: 22 additions & 0 deletions docker/win32-cross-go1.23-qt5.15-dynamic.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.23-bookworm

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -qyy gnupg2 ca-certificates && \
apt-get clean

RUN DEBIAN_FRONTEND=noninteractive \
echo "deb https://pkg.mxe.cc/repos/apt buster main" >/etc/apt/sources.list.d/mxeapt.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 86B72ED9 && \
apt-get update && \
apt-get install -qyy mxe-i686-w64-mingw32.shared-qt5 && \
apt-get clean

ENV PATH=/usr/lib/mxe/usr/bin:$PATH

ENV CXX=i686-w64-mingw32.shared-g++
ENV CC=i686-w64-mingw32.shared-gcc
ENV PKG_CONFIG=i686-w64-mingw32.shared-pkg-config
ENV GOOS=windows
ENV GOARCH=386
ENV CGO_ENABLED=1
ENV GOFLAGS=-buildvcs=false
22 changes: 22 additions & 0 deletions docker/win32-cross-go1.23-qt5.15-static.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.23-bookworm

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -qyy gnupg2 ca-certificates && \
apt-get clean

RUN DEBIAN_FRONTEND=noninteractive \
echo "deb https://pkg.mxe.cc/repos/apt buster main" >/etc/apt/sources.list.d/mxeapt.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 86B72ED9 && \
apt-get update && \
apt-get install -qyy mxe-i686-w64-mingw32.static-qt5 && \
apt-get clean

ENV PATH=/usr/lib/mxe/usr/bin:$PATH

ENV CXX=i686-w64-mingw32.static-g++
ENV CC=i686-w64-mingw32.static-gcc
ENV PKG_CONFIG=i686-w64-mingw32.static-pkg-config
ENV GOOS=windows
ENV GOARCH=386
ENV CGO_ENABLED=1
ENV GOFLAGS=-buildvcs=false
1 change: 0 additions & 1 deletion qt-restricted-extras/qscintilla/gen_qsciscintillabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ const (
QsciScintillaBase__SC_MARKNUM_FOLDERSUB QsciScintillaBase__ = 29
QsciScintillaBase__SC_MARKNUM_FOLDER QsciScintillaBase__ = 30
QsciScintillaBase__SC_MARKNUM_FOLDEROPEN QsciScintillaBase__ = 31
QsciScintillaBase__SC_MASK_FOLDERS QsciScintillaBase__ = 4261412864
QsciScintillaBase__SC_MARGIN_SYMBOL QsciScintillaBase__ = 0
QsciScintillaBase__SC_MARGIN_NUMBER QsciScintillaBase__ = 1
QsciScintillaBase__SC_MARGIN_BACK QsciScintillaBase__ = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !386 && !arm
// +build !386,!arm

package qscintilla

const QsciScintillaBase__SC_MASK_FOLDERS QsciScintillaBase__ = 4261412864

1 change: 0 additions & 1 deletion qt-restricted-extras/qscintilla6/gen_qsciscintillabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ const (
QsciScintillaBase__SC_MARKNUM_FOLDERSUB QsciScintillaBase__ = 29
QsciScintillaBase__SC_MARKNUM_FOLDER QsciScintillaBase__ = 30
QsciScintillaBase__SC_MARKNUM_FOLDEROPEN QsciScintillaBase__ = 31
QsciScintillaBase__SC_MASK_FOLDERS QsciScintillaBase__ = 4261412864
QsciScintillaBase__SC_MARGIN_SYMBOL QsciScintillaBase__ = 0
QsciScintillaBase__SC_MARGIN_NUMBER QsciScintillaBase__ = 1
QsciScintillaBase__SC_MARGIN_BACK QsciScintillaBase__ = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !386 && !arm
// +build !386,!arm

package qscintilla6

const QsciScintillaBase__SC_MASK_FOLDERS QsciScintillaBase__ = 4261412864

3 changes: 2 additions & 1 deletion qt/cflags_windowsqtstatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package qt

/*
#cgo windowsqtstatic CXXFLAGS: -DMIQT_WINDOWSQTSTATIC
#cgo LDFLAGS: -L/usr/lib/mxe/usr/x86_64-w64-mingw32.static/qt5/plugins/platforms -lqwindows -lQt5FontDatabaseSupport -lQt5EventDispatcherSupport -lQt5ThemeSupport -lQt5PlatformCompositorSupport -lQt5AccessibilitySupport -lQt5WindowsUIAutomationSupport -lwtsapi32 -L/usr/lib/mxe/usr/x86_64-w64-mingw32.static/qt5/plugins/styles -lqwindowsvistastyle -luxtheme
#cgo amd64 LDFLAGS: -L/usr/lib/mxe/usr/x86_64-w64-mingw32.static/qt5/plugins/platforms -lqwindows -lQt5FontDatabaseSupport -lQt5EventDispatcherSupport -lQt5ThemeSupport -lQt5PlatformCompositorSupport -lQt5AccessibilitySupport -lQt5WindowsUIAutomationSupport -lwtsapi32 -L/usr/lib/mxe/usr/x86_64-w64-mingw32.static/qt5/plugins/styles -lqwindowsvistastyle -luxtheme
#cgo 386 LDFLAGS: -L/usr/lib/mxe/usr/i686-w64-mingw32.static/qt5/plugins/platforms -lqwindows -lQt5FontDatabaseSupport -lQt5EventDispatcherSupport -lQt5ThemeSupport -lQt5PlatformCompositorSupport -lQt5AccessibilitySupport -lQt5WindowsUIAutomationSupport -lwtsapi32 -L/usr/lib/mxe/usr/i686-w64-mingw32.static/qt5/plugins/styles -lqwindowsvistastyle -luxtheme
*/
import "C"
9 changes: 4 additions & 5 deletions qt/gen_qaccessible.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,10 @@ const (
type QAccessible__RelationFlag int

const (
QAccessible__Label QAccessible__RelationFlag = 1
QAccessible__Labelled QAccessible__RelationFlag = 2
QAccessible__Controller QAccessible__RelationFlag = 4
QAccessible__Controlled QAccessible__RelationFlag = 8
QAccessible__AllRelations QAccessible__RelationFlag = 4294967295
QAccessible__Label QAccessible__RelationFlag = 1
QAccessible__Labelled QAccessible__RelationFlag = 2
QAccessible__Controller QAccessible__RelationFlag = 4
QAccessible__Controlled QAccessible__RelationFlag = 8
)

type QAccessible__InterfaceType int
Expand Down
7 changes: 7 additions & 0 deletions qt/gen_qaccessible_64bit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !386 && !arm
// +build !386,!arm

package qt

const QAccessible__AllRelations QAccessible__RelationFlag = 4294967295

4 changes: 0 additions & 4 deletions qt/gen_qgraphicsitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ const (

type QGraphicsItem__Extension int

const (
QGraphicsItem__UserExtension QGraphicsItem__Extension = 2147483648
)

type QGraphicsPathItem__ int

const (
Expand Down
7 changes: 7 additions & 0 deletions qt/gen_qgraphicsitem_64bit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !386 && !arm
// +build !386,!arm

package qt

const QGraphicsItem__UserExtension QGraphicsItem__Extension = 2147483648

94 changes: 43 additions & 51 deletions qt/gen_qnamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ const (
type KeyboardModifier int

const (
NoModifier KeyboardModifier = 0
ShiftModifier KeyboardModifier = 33554432
ControlModifier KeyboardModifier = 67108864
AltModifier KeyboardModifier = 134217728
MetaModifier KeyboardModifier = 268435456
KeypadModifier KeyboardModifier = 536870912
GroupSwitchModifier KeyboardModifier = 1073741824
KeyboardModifierMask KeyboardModifier = 4261412864
NoModifier KeyboardModifier = 0
ShiftModifier KeyboardModifier = 33554432
ControlModifier KeyboardModifier = 67108864
AltModifier KeyboardModifier = 134217728
MetaModifier KeyboardModifier = 268435456
KeypadModifier KeyboardModifier = 536870912
GroupSwitchModifier KeyboardModifier = 1073741824
)

type Modifier int
Expand All @@ -58,50 +57,48 @@ const (
SHIFT Modifier = 33554432
CTRL Modifier = 67108864
ALT Modifier = 134217728
MODIFIER_MASK Modifier = 4261412864
UNICODE_ACCEL Modifier = 0
)

type MouseButton int

const (
NoButton MouseButton = 0
LeftButton MouseButton = 1
RightButton MouseButton = 2
MiddleButton MouseButton = 4
MidButton MouseButton = 4
BackButton MouseButton = 8
XButton1 MouseButton = 8
ExtraButton1 MouseButton = 8
ForwardButton MouseButton = 16
XButton2 MouseButton = 16
ExtraButton2 MouseButton = 16
TaskButton MouseButton = 32
ExtraButton3 MouseButton = 32
ExtraButton4 MouseButton = 64
ExtraButton5 MouseButton = 128
ExtraButton6 MouseButton = 256
ExtraButton7 MouseButton = 512
ExtraButton8 MouseButton = 1024
ExtraButton9 MouseButton = 2048
ExtraButton10 MouseButton = 4096
ExtraButton11 MouseButton = 8192
ExtraButton12 MouseButton = 16384
ExtraButton13 MouseButton = 32768
ExtraButton14 MouseButton = 65536
ExtraButton15 MouseButton = 131072
ExtraButton16 MouseButton = 262144
ExtraButton17 MouseButton = 524288
ExtraButton18 MouseButton = 1048576
ExtraButton19 MouseButton = 2097152
ExtraButton20 MouseButton = 4194304
ExtraButton21 MouseButton = 8388608
ExtraButton22 MouseButton = 16777216
ExtraButton23 MouseButton = 33554432
ExtraButton24 MouseButton = 67108864
AllButtons MouseButton = 134217727
MaxMouseButton MouseButton = 67108864
MouseButtonMask MouseButton = 4294967295
NoButton MouseButton = 0
LeftButton MouseButton = 1
RightButton MouseButton = 2
MiddleButton MouseButton = 4
MidButton MouseButton = 4
BackButton MouseButton = 8
XButton1 MouseButton = 8
ExtraButton1 MouseButton = 8
ForwardButton MouseButton = 16
XButton2 MouseButton = 16
ExtraButton2 MouseButton = 16
TaskButton MouseButton = 32
ExtraButton3 MouseButton = 32
ExtraButton4 MouseButton = 64
ExtraButton5 MouseButton = 128
ExtraButton6 MouseButton = 256
ExtraButton7 MouseButton = 512
ExtraButton8 MouseButton = 1024
ExtraButton9 MouseButton = 2048
ExtraButton10 MouseButton = 4096
ExtraButton11 MouseButton = 8192
ExtraButton12 MouseButton = 16384
ExtraButton13 MouseButton = 32768
ExtraButton14 MouseButton = 65536
ExtraButton15 MouseButton = 131072
ExtraButton16 MouseButton = 262144
ExtraButton17 MouseButton = 524288
ExtraButton18 MouseButton = 1048576
ExtraButton19 MouseButton = 2097152
ExtraButton20 MouseButton = 4194304
ExtraButton21 MouseButton = 8388608
ExtraButton22 MouseButton = 16777216
ExtraButton23 MouseButton = 33554432
ExtraButton24 MouseButton = 67108864
AllButtons MouseButton = 134217727
MaxMouseButton MouseButton = 67108864
)

type Orientation int
Expand Down Expand Up @@ -255,7 +252,6 @@ const (
MacWindowToolBarButtonHint WindowType = 268435456
BypassGraphicsProxyWidget WindowType = 536870912
NoDropShadowWindowHint WindowType = 1073741824
WindowFullscreenButtonHint WindowType = 2147483648
)

type WindowState int
Expand Down Expand Up @@ -1305,9 +1301,7 @@ const (
ImEnterKeyType InputMethodQuery = 8192
ImAnchorRectangle InputMethodQuery = 16384
ImInputItemClipRectangle InputMethodQuery = 32768
ImPlatformData InputMethodQuery = 2147483648
ImQueryInput InputMethodQuery = 16570
ImQueryAll InputMethodQuery = 4294967295
)

type InputMethodHint int
Expand Down Expand Up @@ -1335,7 +1329,6 @@ const (
ImhEmailCharactersOnly InputMethodHint = 2097152
ImhUrlCharactersOnly InputMethodHint = 4194304
ImhLatinOnly InputMethodHint = 8388608
ImhExclusiveInputMask InputMethodHint = 4294901760
)

type EnterKeyType int
Expand Down Expand Up @@ -1561,7 +1554,6 @@ const (
PinchGesture GestureType = 4
SwipeGesture GestureType = 5
CustomGesture GestureType = 256
LastGestureType GestureType = 4294967295
)

type GestureFlag int
Expand Down
Loading