tinygo-org / tinygo

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

compile failed with `undefined: C._Bool` #3926

Closed Patrick0308 closed 7 months ago

Patrick0308 commented 1 year ago

Environment:

tinygo version: 0.30.0 operating System: macOS architecture: aarch64

Description:

Compilation brakes with an undefined C._Bool

Steps to reproduce:

Given the following Go-code:

package main

/*
  #include "stdbool.h"
  bool test() {
     return true;
  }
*/
import "C"

import "fmt"

func main() {
    fmt.Printf("%s", C._Bool(C.test()))
}

Run

tinygo run main.go

Expected behavior:

❯ tinygo run main.go
%!s(main._Ctype__Bool=true)%    

Actual behavior:

❯ tinygo run main.go
# command-line-arguments
main.go:14:19: undefined: C._Bool
aykevl commented 1 year ago

Well this led me down a rather deep rabbit hole to improve CGo compatibility: https://github.com/tinygo-org/tinygo/pull/3927

I'll look at the actual bug next.

aykevl commented 1 year ago

Here is a fix: https://github.com/tinygo-org/tinygo/pull/3928

Patrick0308 commented 1 year ago

3928 is merged

deadprogram commented 1 year ago

Reopening and tagging to close on next release.

Patrick0308 commented 12 months ago

I build dev branch on my own computer. I tested

package main

/*
  #include "stdbool.h"
  bool test() {
     return true;
  }
*/
import "C"

import "fmt"

func main() {
    fmt.Printf("%s", C._Bool(C.test()))
}

It's ok.

However I tested https://github.com/fermyon/spin/pull/1794 example but building painc. The error log is

Building component tinygo-mysql with `/Users/patrick/projects/tinygo/build/tinygo build -target=wasi -gc=leaking -o main.wasm main.go`
# github.com/fermyon/spin/sdk/go/mysql
../../../tinygo/llvm-project/clang/lib/Headers/stdbool.h:20:14: undefined: C._Bool
Error: Build command for component tinygo-mysql failed with status Exited(1)

Is it another issue?

Patrick0308 commented 12 months ago

@aykevl Any idea?

aykevl commented 7 months ago

@Patrick0308 my guess is that they're shipping their own TinyGo variant, that is still the latest release (and not the dev branch).