tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.21k stars 895 forks source link

Import complex constants from C does not work #3786

Open ysoldak opened 1 year ago

ysoldak commented 1 year ago

When a C constant refers another C constant, it is not possible to use the former w/o explicitly referring the later too in Go code.


Reproducer, from bluetooth library https://github.com/tinygo-org/bluetooth/blob/release/error_sd.go#L15

Replace following line

case e >= C.NRF_ERROR_BASE_NUM && e < C.NRF_ERROR_SDM_BASE_NUM:

with

case e >= 0x0 && e < 0x1000:

And try compile, for example like this:

tinygo build -o test.hex -size=short -target=pca10040-s132v6 ./examples/advertisement

Error emitted:

# tinygo.org/x/bluetooth
s132_nrf52_6.1.1/s132_nrf52_6.1.1_API/include/nrf_error.h:62:48: undefined: C.NRF_ERROR_BASE_NUM
...

Expected outcome: constants resolved correctly w/o need for referencing them explicitly in Go code.

deadprogram commented 1 year ago

@ysoldak is this still an issue with the latest release and/or dev branch?

aykevl commented 1 year ago

I haven't changed anything related to CGo lately, so I'd guess yes.