| 1 |
[!cgo] skip |
| 2 |
[short] skip |
| 3 |
|
| 4 |
cp x.go.txt x.go |
| 5 |
|
| 6 |
# Only allow //go:cgo_ldflag .* in cgo-generated code |
| 7 |
[compiler:gc] cp x_gc.go.txt x.go |
| 8 |
[compiler:gc] ! go build x |
| 9 |
[compiler:gc] stderr '//go:cgo_ldflag .* only allowed in cgo-generated code' |
| 10 |
|
| 11 |
# Ignore _* files |
| 12 |
rm x.go |
| 13 |
! go build . |
| 14 |
stderr 'no Go files' |
| 15 |
cp cgo_yy.go.txt _cgo_yy.go |
| 16 |
! go build . |
| 17 |
stderr 'no Go files' #_* files are ignored... |
| 18 |
|
| 19 |
[compiler:gc] ! go build _cgo_yy.go # ... but if forced, the comment is rejected |
| 20 |
# Actually, today there is a separate issue that _ files named |
| 21 |
# on the command line are ignored. Once that is fixed, |
| 22 |
# we want to see the cgo_ldflag error. |
| 23 |
[compiler:gc] stderr '//go:cgo_ldflag only allowed in cgo-generated code|no Go files' |
| 24 |
|
| 25 |
rm _cgo_yy.go |
| 26 |
|
| 27 |
# Reject #cgo CFLAGS: -fplugin=foo.so |
| 28 |
cp x.go.txt x.go |
| 29 |
cp y_fplugin.go.txt y.go |
| 30 |
! go build x |
| 31 |
stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so' |
| 32 |
|
| 33 |
# Reject #cgo CFLAGS: -lbar -fplugin=foo.so |
| 34 |
cp y_lbar_fplugin.go.txt y.go |
| 35 |
! go build x |
| 36 |
stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so' |
| 37 |
|
| 38 |
# Reject #cgo pkg-config: -foo |
| 39 |
cp y_pkgconfig_dash_foo.txt y.go |
| 40 |
! go build x |
| 41 |
stderr 'invalid pkg-config package name: -foo' |
| 42 |
|
| 43 |
# Reject #cgo pkg-config: @foo |
| 44 |
cp y_pkgconfig_at_foo.txt y.go |
| 45 |
! go build x |
| 46 |
stderr 'invalid pkg-config package name: @foo' |
| 47 |
|
| 48 |
# Reject #cgo pkg-config: --log-file=/tmp/log |
| 49 |
cp y_pkgconfig_log_file.txt y.go |
| 50 |
! go build x |
| 51 |
stderr 'invalid flag in pkg-config: --log-file=/tmp/log' |
| 52 |
|
| 53 |
# Reject #cgo CFLAGS: @foo |
| 54 |
cp y_cflags_at_foo.txt y.go |
| 55 |
! go build x |
| 56 |
stderr 'invalid flag in #cgo CFLAGS: @foo' |
| 57 |
|
| 58 |
# Reject #cgo CFLAGS: -D |
| 59 |
cp y_cflags_dash_d.txt y.go |
| 60 |
! go build x |
| 61 |
stderr 'invalid flag in #cgo CFLAGS: -D without argument' |
| 62 |
|
| 63 |
# Note that -I @foo is allowed because we rewrite it into -I /path/to/src/@foo |
| 64 |
# before the check is applied. There's no such rewrite for -D. |
| 65 |
|
| 66 |
# Reject #cgo CFLAGS: -D @foo |
| 67 |
cp y_cflags_dash_d_space_at_foo.txt y.go |
| 68 |
! go build x |
| 69 |
stderr 'invalid flag in #cgo CFLAGS: -D @foo' |
| 70 |
|
| 71 |
# Reject #cgo CFLAGS -D@foo |
| 72 |
cp y_cflags_dash_d_at_foo.txt y.go |
| 73 |
! go build x |
| 74 |
stderr 'invalid flag in #cgo CFLAGS: -D@foo' |
| 75 |
|
| 76 |
# Check for CFLAGS in commands |
| 77 |
env CGO_CFLAGS=-D@foo |
| 78 |
cp y_no_cflags.txt y.go |
| 79 |
go build -n x |
| 80 |
stderr '-D@foo' |
| 81 |
|
| 82 |
-- go.mod -- |
| 83 |
module x |
| 84 |
|
| 85 |
go 1.16 |
| 86 |
-- x_gc.go.txt -- |
| 87 |
package x |
| 88 |
|
| 89 |
//go:cgo_ldflag "-fplugin=foo.so" |
| 90 |
|
| 91 |
import "C" |
| 92 |
-- cgo_yy.go.txt -- |
| 93 |
package x |
| 94 |
|
| 95 |
//go:cgo_ldflag "-fplugin=foo.so" |
| 96 |
|
| 97 |
import "C" |
| 98 |
-- x.go.txt -- |
| 99 |
package x |
| 100 |
-- y_fplugin.go.txt -- |
| 101 |
package x |
| 102 |
// #cgo CFLAGS: -fplugin=foo.so |
| 103 |
import "C" |
| 104 |
-- y_lbar_fplugin.go.txt -- |
| 105 |
package x |
| 106 |
// #cgo CFLAGS: -Ibar -fplugin=foo.so |
| 107 |
import "C" |
| 108 |
-- y_pkgconfig_dash_foo.txt -- |
| 109 |
package x |
| 110 |
// #cgo pkg-config: -foo |
| 111 |
import "C" |
| 112 |
-- y_pkgconfig_at_foo.txt -- |
| 113 |
package x |
| 114 |
// #cgo pkg-config: @foo |
| 115 |
import "C" |
| 116 |
-- y_pkgconfig_log_file.txt -- |
| 117 |
package x |
| 118 |
// #cgo pkg-config: --log-file=/tmp/log |
| 119 |
import "C" |
| 120 |
-- y_cflags_at_foo.txt -- |
| 121 |
package x |
| 122 |
// #cgo CFLAGS: @foo |
| 123 |
import "C" |
| 124 |
-- y_cflags_dash_d.txt -- |
| 125 |
package x |
| 126 |
// #cgo CFLAGS: -D |
| 127 |
import "C" |
| 128 |
-- y_cflags_dash_d_space_at_foo.txt -- |
| 129 |
package x |
| 130 |
// #cgo CFLAGS: -D @foo |
| 131 |
import "C" |
| 132 |
-- y_cflags_dash_d_at_foo.txt -- |
| 133 |
package x |
| 134 |
// #cgo CFLAGS: -D@foo |
| 135 |
import "C" |
| 136 |
-- y_no_cflags.txt -- |
| 137 |
package x |
| 138 |
import "C" |