genbindings: prevent using qt6 qsharedmemory on android

This commit is contained in:
mappu 2025-02-15 17:10:03 +13:00
parent f8e429b362
commit da874c95ed
3 changed files with 52 additions and 0 deletions

View File

@ -105,6 +105,35 @@ func Widgets_AllowHeader(fullpath string) bool {
return true
}
type AllowedPlatformInfo interface {
GoBuildTag() string
CxxIf() string
}
type AndroidBlockedPlatform struct{}
func (abp AndroidBlockedPlatform) GoBuildTag() string {
return `!android`
}
func (abp AndroidBlockedPlatform) CxxIf() string {
return `! defined(Q_OS_ANDROID)`
}
func HeaderPlatformRestriction(fullpath string) AllowedPlatformInfo {
fname := filepath.Base(fullpath)
if fname == `qsharedmemory.h` {
// Not implemented on Android nor iOS
// Qt 5: Classes are present but do not work
// Qt 6: Class definition is not present and our generated subclass fails to compile
return AndroidBlockedPlatform{}
}
// No platform restriction
return nil
}
func ImportHeaderForClass(className string) bool {
if className[0] != 'Q' {
return false

View File

@ -931,6 +931,16 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
ret.WriteString(`#include <` + filename + ">\n")
ret.WriteString(`#include "gen_` + filename + "\"\n")
// Perform any platform checks
// n.b. The Q_OS_ variable is defined usually indirectly from another Qt
// header, so it should be checked only after all the other includes,
// although that seems suboptimal
platformRestriction := HeaderPlatformRestriction(filename)
if platformRestriction != nil {
ret.WriteString(`#if ` + platformRestriction.CxxIf() + "\n\n")
}
// Write prototypes for functions that the host language bindings should export
// for virtual function overrides
@ -1410,5 +1420,11 @@ extern "C" {
}
}
//
if platformRestriction != nil {
ret.WriteString(`#endif //` + platformRestriction.CxxIf() + "\n\n")
}
return ret.String(), nil
}

View File

@ -669,6 +669,13 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue
func emitGo(src *CppParsedHeader, headerName string, packageName string) (string, string, error) {
ret := strings.Builder{}
platformRestriction := HeaderPlatformRestriction(headerName)
if platformRestriction != nil {
ret.WriteString(`//go:build ` + platformRestriction.GoBuildTag() + "\n" +
`// +build ` + platformRestriction.GoBuildTag() + "\n\n")
}
ret.WriteString(`package ` + path.Base(packageName) + `
/*