Skip to content
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

crypto/x509: exporting staticlib with ios_sdk failed with CGO_ENABLED=1 #39503

Closed
nodece opened this issue Jun 10, 2020 · 4 comments
Closed

crypto/x509: exporting staticlib with ios_sdk failed with CGO_ENABLED=1 #39503

nodece opened this issue Jun 10, 2020 · 4 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@nodece
Copy link

nodece commented Jun 10, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.1 darwin/amd64

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.5
BuildVersion:	19F101

What did you do?

clangwrap.sh

#!/bin/sh
# This uses the latest available iOS SDK, which is recommended.
# To select a specific SDK, run 'xcodebuild -showsdks'
# to see the available SDKs and replace iphoneos with one of them.
SDK_PATH=`xcrun --sdk $SDK --show-sdk-path`
# cmd/cgo doesn't support llvm-gcc-4.2, so we have to use clang.
CLANG=`xcrun --sdk $SDK --find clang`
exec $CLANG -arch $CLANGARCH -isysroot $SDK_PATH "$@"

build.sh

# iPhoneSimulator
export CGO_ENABLED=1
export GOARCH="amd64"
export CLANGARCH="x86_64"
export SDK=iphonesimulator13.5
export CC=$PWD/clangwrap.sh
export CXX=$PWD/clangwrap.sh
go build -buildmode=c-archive -o libtest_amd64.a main.go

build

bash ./build.sh

Log

# crypto/x509
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:43:57: error: use of undeclared identifier 'kSecTrustSettingsDomainUser'
        OSStatus err = SecTrustSettingsCopyTrustSettings(cert, kSecTrustSettingsDomainUser, &trustSettings);
                                                               ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:50:49: error: use of undeclared identifier 'kSecTrustSettingsDomainAdmin'
                err = SecTrustSettingsCopyTrustSettings(cert, kSecTrustSettingsDomainAdmin, &trustSettings);
                                                              ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:57:10: error: use of undeclared identifier 'kSecTrustSettingsResultUnspecified'; did you mean 'kSecTrustResultUnspecified'?
                return kSecTrustSettingsResultUnspecified;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                       kSecTrustResultUnspecified
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrust.h:89:5: note: 'kSecTrustResultUnspecified' declared here
    kSecTrustResultUnspecified  CF_ENUM_AVAILABLE(10_3, 2_0) = 4,
    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:64:10: error: use of undeclared identifier 'kSecTrustSettingsResultTrustRoot'
                return kSecTrustSettingsResultTrustRoot;
                       ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:100:13: error: use of undeclared identifier 'kSecTrustSettingsResultTrustRoot'; did you mean '_kSecTrustSettingsResult'?
                        result = kSecTrustSettingsResultTrustRoot;
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                 _kSecTrustSettingsResult
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:70:14: note: '_kSecTrustSettingsResult' declared here
        CFStringRef _kSecTrustSettingsResult = CFStringCreateWithCString(
                    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:108:17: error: use of undeclared identifier 'kSecTrustSettingsResultTrustRoot'; did you mean '_kSecTrustSettingsResult'?
                if (result == kSecTrustSettingsResultTrustRoot) {
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                              _kSecTrustSettingsResult
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:70:14: note: '_kSecTrustSettingsResult' declared here
        CFStringRef _kSecTrustSettingsResult = CFStringCreateWithCString(
                    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:110:24: error: use of undeclared identifier 'kSecTrustSettingsResultTrustAsRoot'; did you mean '_kSecTrustSettingsResult'?
                } else if (result == kSecTrustSettingsResultTrustAsRoot) {
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                     _kSecTrustSettingsResult
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:70:14: note: '_kSecTrustSettingsResult' declared here
        CFStringRef _kSecTrustSettingsResult = CFStringCreateWithCString(
                    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:112:24: error: use of undeclared identifier 'kSecTrustSettingsResultDeny'; did you mean '_kSecTrustSettingsResult'?
                } else if (result == kSecTrustSettingsResultDeny) {
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                                     _kSecTrustSettingsResult
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:70:14: note: '_kSecTrustSettingsResult' declared here
        CFStringRef _kSecTrustSettingsResult = CFStringCreateWithCString(
                    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:125:12: error: use of undeclared identifier 'kSecTrustSettingsResultUnspecified'; did you mean 'kSecTrustResultUnspecified'?
                result = kSecTrustSettingsResultUnspecified;
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                         kSecTrustResultUnspecified
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrust.h:89:5: note: 'kSecTrustResultUnspecified' declared here
    kSecTrustResultUnspecified  CF_ENUM_AVAILABLE(10_3, 2_0) = 4,
    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:166:73: error: use of undeclared identifier 'kSecTrustSettingsResultInvalid'; did you mean 'kSecTrustResultInvalid'?
                fprintf(stderr, "crypto/x509: kSecTrustSettingsResultInvalid = %d\n", kSecTrustSettingsResultInvalid);
                                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                                      kSecTrustResultInvalid
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrust.h:85:5: note: 'kSecTrustResultInvalid' declared here
    kSecTrustResultInvalid  CF_ENUM_AVAILABLE(10_3, 2_0) = 0,
    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:167:75: error: use of undeclared identifier 'kSecTrustSettingsResultTrustRoot'
                fprintf(stderr, "crypto/x509: kSecTrustSettingsResultTrustRoot = %d\n", kSecTrustSettingsResultTrustRoot);
                                                                                        ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:168:77: error: use of undeclared identifier 'kSecTrustSettingsResultTrustAsRoot'
                fprintf(stderr, "crypto/x509: kSecTrustSettingsResultTrustAsRoot = %d\n", kSecTrustSettingsResultTrustAsRoot);
                                                                                          ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:169:70: error: use of undeclared identifier 'kSecTrustSettingsResultDeny'
                fprintf(stderr, "crypto/x509: kSecTrustSettingsResultDeny = %d\n", kSecTrustSettingsResultDeny);
                                                                                   ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:170:77: error: use of undeclared identifier 'kSecTrustSettingsResultUnspecified'; did you mean 'kSecTrustResultUnspecified'?
                fprintf(stderr, "crypto/x509: kSecTrustSettingsResultUnspecified = %d\n", kSecTrustSettingsResultUnspecified);
                                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                                          kSecTrustResultUnspecified
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrust.h:89:5: note: 'kSecTrustResultUnspecified' declared here
    kSecTrustResultUnspecified  CF_ENUM_AVAILABLE(10_3, 2_0) = 4,
    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:176:2: error: use of undeclared identifier 'SecTrustSettingsDomain'
        SecTrustSettingsDomain domains[] = { kSecTrustSettingsDomainSystem,
        ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:179:26: error: use of undeclared identifier 'domains'
        int numDomains = sizeof(domains)/sizeof(SecTrustSettingsDomain);
                                ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:179:42: error: use of undeclared identifier 'SecTrustSettingsDomain'
        int numDomains = sizeof(domains)/sizeof(SecTrustSettingsDomain);
                                                ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:189:51: error: use of undeclared identifier 'domains'
                OSStatus err = SecTrustSettingsCopyCertificates(domains[i], &certs);
                                                                ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:202:8: error: use of undeclared identifier 'domains'
                        if (domains[i] == kSecTrustSettingsDomainSystem) {
                            ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:202:22: error: use of undeclared identifier 'kSecTrustSettingsDomainSystem'
                        if (domains[i] == kSecTrustSettingsDomainSystem) {
                                          ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:207:14: error: use of undeclared identifier 'kSecTrustSettingsResultTrustRoot'
                                result = kSecTrustSettingsResultTrustRoot;
                                         ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:235:18: error: use of undeclared identifier 'kSecTrustSettingsResultTrustRoot'
                        if (result == kSecTrustSettingsResultTrustRoot) {
                                      ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:243:25: error: use of undeclared identifier 'kSecTrustSettingsResultTrustAsRoot'
                        } else if (result == kSecTrustSettingsResultTrustAsRoot) {
                                             ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:251:25: error: use of undeclared identifier 'kSecTrustSettingsResultDeny'
                        } else if (result == kSecTrustSettingsResultDeny) {
                                             ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:253:25: error: use of undeclared identifier 'kSecTrustSettingsResultUnspecified'; did you mean 'kSecTrustResultUnspecified'?
                        } else if (result == kSecTrustSettingsResultUnspecified) {
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                             kSecTrustResultUnspecified
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrust.h:89:5: note: 'kSecTrustResultUnspecified' declared here
    kSecTrustResultUnspecified  CF_ENUM_AVAILABLE(10_3, 2_0) = 4,
    ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:264:30: error: use of undeclared identifier 'kSecFormatX509Cert'
                        err = SecItemExport(cert, kSecFormatX509Cert, kSecItemPemArmour, NULL, &data);
                                                  ^
/usr/local/Cellar/go/1.14.1/libexec/src/crypto/x509/root_cgo_darwin.go:264:50: error: use of undeclared identifier 'kSecItemPemArmour'
                        err = SecItemExport(cert, kSecFormatX509Cert, kSecItemPemArmour, NULL, &data);
                                                                      ^
27 errors generated.
@odeke-em odeke-em changed the title cgo/crypto/x509: exporting staticlib with ios_sdk failed crypto/x509: exporting staticlib with ios_sdk failed with CGO_ENABLED=1 Jun 10, 2020
@odeke-em
Copy link
Member

Thank you for this report @nodece and welcome to the Go project!

Kindly cc-ing @FiloSottile @katiehockman.

@odeke-em odeke-em added mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 10, 2020
@eliasnaur
Copy link
Contributor

go build -buildmode=c-archive -o libtest_amd64.a main.go

I believe you need -tags=ios to build for iOS:

$ go build -buildmode=c-archive -tags=ios -o libtest_amd64.a main.go

See also #38485.

@nodece
Copy link
Author

nodece commented Jun 11, 2020

@eliasnaur good, It works fine. I want to know where I can find supported tags.

@eliasnaur
Copy link
Contributor

I don't know where supported tags are listed, sorry. Please ask your question on the golang-nuts list. FWIW, the ios tag is probably being replaced with GOOS=ios when #38485 is resolved.

@golang golang locked and limited conversation to collaborators Jun 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants