Skip to content

Conversation

@aykevl
Copy link
Member

@aykevl aykevl commented Jan 27, 2024

I managed to get CGo sort-of working in VSCode (meaning that it will typecheck code in the IDE itself) using a few crude hacks, but it requires a few minor changes to the TinyGo standard library.

I intend to eventually add this support in the TinyGo extension for VSCode directly, but for now I've manually updated .vscode/settings.json to get IDE support. In any case, it would be nice to have this for when I hopefully add this to the TinyGo extension eventually.

For reference, I'm using TinyGo target "gopher-badge" in VSCode with the following custom settings:

{
    "cmake.configureOnOpen": false,
    "go.toolsEnvVars": {
        "CGO_ENABLED": "1",
        "CC": "clang",
        "GOOS": "linux",
        "GOARCH": "arm",{
        "CGO_CFLAGS": "-Werror -fshort-enums -fomit-frame-pointer -mfloat-abi=soft -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -nostdlibinc -isystem /home/ayke/.cache/tinygo/picolibc-thumbv6m-unknown-unknown-eabi-cortex-m0plus/include -isystem /home/ayke/src/tinygo/tinygo/lib/picolibc/newlib/libc/include -isystem /home/ayke/src/tinygo/tinygo/lib/picolibc/newlib/libc/tinystdio -Oz --target=thumbv6m-unknown-unknown-eabi -mcpu=cortex-m0plus -mthumb -fno-PIC",
        "GOROOT": "/home/ayke/.cache/tinygo/goroot-8d8f8a7da5d85cd177e3196b59dcd519d76b00dc6a0aae2635059910f11c4e8c",
        "GOFLAGS": "-tags=cortexm,baremetal,linux,arm,rp2040,rp,gopher_badge,math_big_pure_go,gc.conservative,scheduler.tasks,serial.usb",
        "CCC_OVERRIDE_OPTIONS": "+-mthumb",
    },
}

Some notes:

  • I got the list of CFlags by patching the tinygo binary, I should make a separate PR for that too.
  • I had to remove the tinygo build tag to get things to work (the tinygo files often can't be parsed by upstream CGo).
  • The CCC_OVERRIDE_OPTIONS is the especially crude hack: Go adds -marm and there doesn't appear to be a way to override it, except using this special (undocumented) environment variable. It's really meant to be used for tests, not for production code.

I managed to get CGo sort-of working in VSCode (meaning that it will
typecheck code in the IDE itself) using a few crude hacks, but it
requires a few minor changes to the TinyGo standard library.

I intend to eventually add this support in the TinyGo extension for
VSCode directly, but for now I've manually updated .vscode/settings.json
to get IDE support. In any case, it would be nice to have this for when
I hopefully add this to the TinyGo extension eventually.
@github-actions
Copy link

Size difference with the dev branch:

Binary size difference
drivers/sizes-pr.txt has more commands than drivers/sizes-dev.txt
    tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
 flash                          ram
 before   after   diff          before   after   diff
  60736   60736      0   0.00%    6160    6160      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
   9612    9612      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  13232   13232      0   0.00%    6780    6780      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
   8600    8600      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  11584   11584      0   0.00%    6556    6556      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
   9660    9660      0   0.00%    4752    4752      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
   8180    8180      0   0.00%    2304    2304      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
   8220    8220      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   7508    7508      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  70220   70220      0   0.00%    3676    3676      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
  63156   63156      0   0.00%    6160    6160      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  27644   27644      0   0.00%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  63264   63264      0   0.00%    6192    6192      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  12212   12212      0   0.00%    4804    4804      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
   8128    8128      0   0.00%    3332    3332      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  22088   22088      0   0.00%    3528    3528      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
  69044   69044      0   0.00%    6332    6332      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/main.go
   4704    4704      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
  24792   24792      0   0.00%    6292    6292      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/espat/espconsole/main.go
  24940   24940      0   0.00%    6292    6292      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/espat/esphub/main.go
  24792   24792      0   0.00%    6292    6292      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/espat/espstation/main.go
  68620   68620      0   0.00%    6940    6940      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  64652   64652      0   0.00%    8980    8980      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
   7040    7040      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
  67468   67468      0   0.00%    6336    6336      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
  67896   67896      0   0.00%    6472    6472      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
   8260    8260      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
   5612    5612      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
   5656    5656      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  10440   10440      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
  14496   14496      0   0.00%    6556    6556      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  16868   16868      0   0.00%    2344    2344      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  10056   10056      0   0.00%    6900    6900      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  10696   10696      0   0.00%    4852    4852      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
  28996   28996      0   0.00%   38060   38060      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  10080   10080      0   0.00%    6908    6908      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
  10784   10784      0   0.00%    4860    4860      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
 959936  959936      0   0.00%  220896  220896      0   0.00%

@ysoldak
Copy link
Contributor

ysoldak commented Feb 8, 2024

Thank you for looking into this. I'm pretty annoyed with VSCode red marks all over when working on something that uses our bluetooth lib.

@deadprogram
Copy link
Member

Thanks for adding this @aykevl and to @ysoldak for review. Now merging.

@deadprogram deadprogram merged commit 7486277 into dev Feb 19, 2024
@deadprogram deadprogram deleted the gopls-cgo branch February 19, 2024 14:49
@deadprogram
Copy link
Member

Looks like this might have had an unintended side effect @aykevl

Please see https://github.com/tinygo-org/drivers/actions/runs/7961592170/job/21733165140#step:8:509

@aykevl
Copy link
Member Author

aykevl commented Feb 19, 2024

@deadprogram pretty sure that's unrelated. I've seen many weird flaky tests lately, I think we have another memory corruption error.

mikesmitty added a commit to mikesmitty/tinygo that referenced this pull request Mar 15, 2025
deadprogram pushed a commit that referenced this pull request Mar 16, 2025
* machine/rp2350: add flash support for rp2350
* combine duplicate files
* clean things up and group by source file
* add stubbed out xip cache clean func if needed in the future
* update flash_enable_xip_via_boot2
* remove unused macros and fix inconsistent formatting
* make flash size configurable like rp2040
* add missing flash size configs
* retain big Go CGo compatibility per #4103
* clarify CS0_SIZE source and remove single-use typedef
deadprogram pushed a commit that referenced this pull request Aug 16, 2025
* machine/rp2350: add flash support for rp2350
* combine duplicate files
* clean things up and group by source file
* add stubbed out xip cache clean func if needed in the future
* update flash_enable_xip_via_boot2
* remove unused macros and fix inconsistent formatting
* make flash size configurable like rp2040
* add missing flash size configs
* retain big Go CGo compatibility per #4103
* clarify CS0_SIZE source and remove single-use typedef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants