Skip to content

Commit 73cc5f8

Browse files
committed
Fix client lib builds
1 parent c5b58c4 commit 73cc5f8

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package common
2+
3+
import "strconv"
4+
5+
// IsIntegerConst reports whether a scanned constant should be treated as an
6+
// integer constant in generated client constant blocks.
7+
func IsIntegerConst(value interface{}, goType string) bool {
8+
base, _, _ := NormalizeGoType(goType)
9+
switch base {
10+
case "int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", "byte":
11+
return true
12+
}
13+
14+
switch v := value.(type) {
15+
case int, int64, uint64:
16+
return true
17+
case string:
18+
if _, err := strconv.ParseInt(v, 0, 64); err == nil {
19+
return true
20+
}
21+
if _, err := strconv.ParseUint(v, 0, 64); err == nil {
22+
return true
23+
}
24+
}
25+
26+
return false
27+
}

internal/codegen/generator/cpp/device_header.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ func generateDeviceHeader(logger *slog.Logger, devicesDir, deviceName string, md
272272
}
273273
}
274274

275+
constants := make([]scanner.ConstantInfo, 0, len(devicePkg.Constants))
276+
for _, c := range devicePkg.Constants {
277+
if !common.IsIntegerConst(c.Value, c.Type) {
278+
continue
279+
}
280+
constants = append(constants, c)
281+
}
282+
275283
data := struct {
276284
Header string
277285
DeviceName string
@@ -285,7 +293,7 @@ func generateDeviceHeader(logger *slog.Logger, devicesDir, deviceName string, md
285293
}{
286294
Header: writeFileHeader(),
287295
DeviceName: deviceName,
288-
Constants: devicePkg.Constants,
296+
Constants: constants,
289297
Maps: devicePkg.Maps,
290298
HasInput: hasInput,
291299
HasOutput: hasOutput,

internal/codegen/generator/csharp/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func groupConstantsByPrefix(constants []scanner.ConstantInfo) []enumGroup {
113113
groups := make(map[string]*enumGroup)
114114

115115
for _, c := range constants {
116+
if !common.IsIntegerConst(c.Value, c.Type) {
117+
continue
118+
}
119+
116120
prefix := common.ExtractPrefix(c.Name)
117121
if prefix == "" {
118122
continue

internal/codegen/generator/rust/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func generateConstants(logger *slog.Logger, deviceDir string, deviceName string,
8888
}
8989

9090
for _, c := range devicePkg.Constants {
91+
if !common.IsIntegerConst(c.Value, c.Type) {
92+
continue
93+
}
9194
rustType := goTypeToRust(c.Type)
9295
value := formatConstValue(c.Value, c.Type)
9396
constants = append(constants, rustConstant{

0 commit comments

Comments
 (0)