{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/16981","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/16981/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/16981/comments","events_url":"https://api.github.com/repos/golang/go/issues/16981/events","html_url":"https://github.com/golang/go/issues/16981","id":174911777,"number":16981,"title":"cgo: if CGO_ENABLED=0, cgo files are silently ignored","user":{"login":"FiloSottile","id":1225294,"avatar_url":"https://avatars.githubusercontent.com/u/1225294?v=3","gravatar_id":"","url":"https://api.github.com/users/FiloSottile","html_url":"https://github.com/FiloSottile","followers_url":"https://api.github.com/users/FiloSottile/followers","following_url":"https://api.github.com/users/FiloSottile/following{/other_user}","gists_url":"https://api.github.com/users/FiloSottile/gists{/gist_id}","starred_url":"https://api.github.com/users/FiloSottile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FiloSottile/subscriptions","organizations_url":"https://api.github.com/users/FiloSottile/orgs","repos_url":"https://api.github.com/users/FiloSottile/repos","events_url":"https://api.github.com/users/FiloSottile/events{/privacy}","received_events_url":"https://api.github.com/users/FiloSottile/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-03T18:52:51Z","updated_at":"2016-09-04T06:07:31Z","closed_at":null,"body":"### What version of Go are you using (`go version`)?\r\n```\r\ngo version go1.7 darwin/amd64\r\n```\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\n```\r\nGOARCH=\"amd64\"\r\nGOBIN=\"\"\r\nGOEXE=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"darwin\"\r\nGOOS=\"darwin\"\r\nGOPATH=\"/Users/filippo/go\"\r\nGORACE=\"\"\r\nGOROOT=\"/usr/local/Cellar/go/1.7/libexec\"\r\nGOTOOLDIR=\"/usr/local/Cellar/go/1.7/libexec/pkg/tool/darwin_amd64\"\r\nCC=\"clang\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v8/xdj2snz51sg2m2bnpmwl_91c0000gn/T/go-build466071352=/tmp/go-build -gno-record-gcc-switches -fno-common\"\r\nCXX=\"clang++\"\r\nCGO_ENABLED=\"1\"\r\n```\r\n\r\n### What did you do?\r\nBuilt a package with both cgo and non-cgo files, with CGO_ENABLED=0:\r\n```\r\nCGO_ENABLED=0 go get github.com/FiloSottile/justcgo/plusgo\r\n```\r\n\r\n### What did you expect to see?\r\nAn error about not being able to build cgo files.\r\n\r\n### What did you see instead?\r\ncgo files were silently dropped, and the binary built anyway.\r\n\r\n---\r\n\r\nThis is the simplified case, which might seem like the correct behavior, but how I found this was by cross-compiling `github.com/mattn/go-sqlite3/_example/simple`, which imports `_ github.com/mattn/go-sqlite3`, which register a `database/sql` driver.\r\n\r\nI expected the command to fail, instead it built a binary. I was very puzzled. Eventually, I tried that binary and it complained about an unknown driver. Turns out `github.com/mattn/go-sqlite3` has one file with no cgo directives: `doc.go`. Which makes failures to compile the package completely silent.\r\n\r\nI don't think that should be intended behavior. A cgo-specific error is much more useful than an attempt at building anyway, which can lead to the confusing:\r\n\r\n* broken binary (missing side effects)\r\n* \"no buildable files found\"\r\n* variable/method/function not found"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/244586147","html_url":"https://github.com/golang/go/issues/16981#issuecomment-244586147","issue_url":"https://api.github.com/repos/golang/go/issues/16981","id":244586147,"user":{"login":"rakyll","id":108380,"avatar_url":"https://avatars.githubusercontent.com/u/108380?v=3","gravatar_id":"","url":"https://api.github.com/users/rakyll","html_url":"https://github.com/rakyll","followers_url":"https://api.github.com/users/rakyll/followers","following_url":"https://api.github.com/users/rakyll/following{/other_user}","gists_url":"https://api.github.com/users/rakyll/gists{/gist_id}","starred_url":"https://api.github.com/users/rakyll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rakyll/subscriptions","organizations_url":"https://api.github.com/users/rakyll/orgs","repos_url":"https://api.github.com/users/rakyll/repos","events_url":"https://api.github.com/users/rakyll/events{/privacy}","received_events_url":"https://api.github.com/users/rakyll/received_events","type":"User","site_admin":false},"created_at":"2016-09-04T06:07:31Z","updated_at":"2016-09-04T06:07:31Z","body":"> Did you mean 1.4? \r\n\r\nRejecting the C files introduced in 1.4. Sorry, it sounds like skipping them has introduced.\r\n`go build -compiler=gc` prohibiting builds with C files (when CGO_ENABLED=0) happened at https://codereview.appspot.com/149720043 (go1.4).\r\n\r\nIt is more of a requirement now to ship a package with cgo and !cgo implementations because C compilers are not primarily required for Go. Implicitly scoping C files without a build tag to cgo builds is not bad but handy.\r\n\r\nsqlite package should maybe add cgo build tag to restrict itself to cgo builds."}}
{"actor":{"display_login":"rakyll"}}