-
Notifications
You must be signed in to change notification settings - Fork 851
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
cgo: add support for printf #4101
base: dev
Are you sure you want to change the base?
Conversation
Size difference with the dev branch: Binary size differencenot the same command! tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650 go: downloading tinygo.org/x/tinyfont v0.3.0 flash ram before after diff before after diff 16744 16744 0 0.00% 4308 4308 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650 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 9652 9652 0 0.00% 4740 4740 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go 13476 13476 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 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 29404 29404 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 263072 263072 0 0.00% 46720 46720 0 0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow 11784 11784 0 0.00% 4772 4772 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go 13840 13840 0 0.00% 6556 6556 0 0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go 26052 26052 0 0.00% 2312 2312 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go 12360 12360 0 0.00% 4780 4780 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go 10800 10800 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go 10004 10004 0 0.00% 4764 4764 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go 10424 10424 0 0.00% 4772 4772 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go 9692 9692 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go 66752 66752 0 0.00% 6160 6160 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go 22884 22884 0 0.00% 2424 2424 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go 22892 22892 0 0.00% 4468 4468 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go 8320 8320 0 0.00% 4740 4740 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go 8232 8232 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go 74908 74908 0 0.00% 7444 7444 0 0.00% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go 12124 12124 0 0.00% 3336 3336 0 0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go 6068 6068 0 0.00% 3272 3272 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go 5104 5104 0 0.00% 2264 2264 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go 10392 10392 0 0.00% 3312 3312 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw 2697 2697 0 0.00% 556 556 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo 13652 13652 0 0.00% 3384 3384 0 0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/sgp30 7940 7940 0 0.00% 6780 6780 0 0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go 56400 56400 0 0.00% 3652 3652 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go 56456 56456 0 0.00% 3660 3660 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go 56372 56372 0 0.00% 3652 3652 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go 6460 6460 0 0.00% 2272 2272 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/i2c_128x32/main.go 5996 5996 0 0.00% 2264 2264 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/spi_128x64/main.go 5676 5676 0 0.00% 2264 2264 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go 6612 6612 0 0.00% 2264 2264 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go 6512 6512 0 0.00% 2264 2264 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go 17044 17044 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go 10292 10292 0 0.00% 4516 4516 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone 9972 9972 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go 9396 9396 0 0.00% 6772 6772 0 0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go 12468 12468 0 0.00% 6984 6984 0 0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go 15708 15708 0 0.00% 4740 4740 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go 13736 13736 0 0.00% 4740 4740 0 0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go 6380 6380 0 0.00% 2304 2304 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go 6004 6004 0 0.00% 2296 2296 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go 6260 6260 0 0.00% 2304 2304 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go 6800 6800 0 0.00% 4772 4772 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812 5506 5506 0 0.00% 9502 9502 0 0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3 ./examples/ws2812 61648 61648 0 0.00% 5912 5912 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go 1709 1709 0 0.00% 596 596 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/ws2812 1040 1040 0 0.00% 178 178 0 0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812 32048 32048 0 0.00% 4772 4772 0 0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go 16500 16500 0 0.00% 4716 4716 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go 11128 11128 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go 12784 12784 0 0.00% 4772 4772 0 0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go 6676 6676 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go 8596 8596 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go 6640 6640 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go 9212 9212 0 0.00% 4740 4740 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go 7288 7288 0 0.00% 3304 3304 0 0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go 6916 6916 0 0.00% 2252 2252 0 0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go 13060 13060 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go 8304 8304 0 0.00% 4748 4748 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go 76488 76488 0 0.00% 6300 6300 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go 36356 36356 0 0.00% 3972 3972 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/ 70576 70576 0 0.00% 6308 6308 0 0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/ 7276 7276 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/ 70096 70096 0 0.00% 6312 6312 0 0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/ 70488 70488 0 0.00% 6308 6308 0 0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/ 12052 12052 0 0.00% 3288 3288 0 0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go 8840 8840 0 0.00% 4740 4740 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go 9272 9272 0 0.00% 5236 5236 0 0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go 71960 71960 0 0.00% 10716 10716 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/ 60580 60580 0 0.00% 8200 8200 0 0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/ 10144 10144 0 0.00% 6780 6780 0 0.00% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/ 8892 8892 0 0.00% 3260 3260 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go 14532 14532 0 0.00% 4916 4916 0 0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/ 26260 26260 0 0.00% 3376 3376 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go 11156 11156 0 0.00% 4236 4236 0 0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go 11180 11180 0 0.00% 3300 3300 0 0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go 10284 10284 0 0.00% 3340 3340 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go 8568 8568 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go 9468 9468 0 0.00% 4748 4748 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go 81740 81740 0 0.00% 6572 6572 0 0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/ 15708 15708 0 0.00% 4860 4860 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go 9776 9776 0 0.00% 3280 3280 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go 7716 7716 0 0.00% 4732 4732 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go 65920 65920 0 0.00% 4792 4792 0 0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go 61264 61264 0 0.00% 3760 3760 0 0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go 64392 64392 0 0.00% 6232 6232 0 0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go 9192 9192 0 0.00% 3272 3272 0 0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go 12236 12236 0 0.00% 3308 3308 0 0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi 8384 8384 0 0.00% 3744 3744 0 0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt 84916 84916 0 0.00% 5148 5148 0 0.00% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/ 3082152 3082152 0 0.00% 638176 638176 0 0.00% |
See, that's why I added this test a while back. This should not have resulted in a code size change, yet it does. EDIT: this is llvm/llvm-project#52 |
c7ee956
to
5252e7a
Compare
Found one remaining issue, which appears to be a wasmtime bug: bytecodealliance/wasmtime#7833 |
This updates the list of builtins to the one in LLVM 17 (which is our current version) and addes GENERIC_TF_SOURCES, which contains long double floating point builtins (80 bit, 128 bit, etc). This is needed for full printf support in the next commit.
72f0403
to
1a530ae
Compare
@aykevl there still appears to be some issue with the Windows build on this PR. |
This flushes stdio, so that functions like puts and printf write out all buffered data even if the output isn't connected to a terminal. For discussion, see: bytecodealliance/wasmtime#7833
Yeah, I think I need to debug this on an actual Windows system. |
The C printf function is sometimes needed for C files included using CGo. This commit makes sure they're available on all systems where CGo is fully supported (that is, everywhere except on AVR). For baremetal systems using picolibc, I've picked the integer-only version of printf to save on flash size. We might want to consider providing a way to pick the floating point version instead, if needed.
That CI failure should be fixed now. I just had to fix this one line: if err != nil {
return BuildResult{}, err
}
- unlock()
+ defer unlock()
libcDependencies = append(libcDependencies, job)
libcDependencies = append(libcDependencies, makeMinGWExtraLibs(tmpdir, config.GOARCH())...)
case "": No idea why only this library didn't have the defer while the others did. |
The C printf function is sometimes needed for C files included using CGo. This PR makes sure they're available on all systems where CGo is fully supported (that is, everywhere except on AVR).
For baremetal systems using picolibc, I've picked the integer-only version of printf to save on flash size. In the future we might want to consider providing a way to pick the floating point version instead, if needed.