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

Cannot cross compile Go HTTP server + CGO code from Linux -> macOS #11041

Closed
slimsag opened this issue Mar 3, 2022 · 1 comment
Closed

Cannot cross compile Go HTTP server + CGO code from Linux -> macOS #11041

slimsag opened this issue Mar 3, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@slimsag
Copy link
Sponsor Contributor

slimsag commented Mar 3, 2022

Zig Version

0.10.0-dev.670+e1a535360

Steps to Reproduce

This issue only occurs in programs that import Go's networking packages AND CGO. When CGO is being used, Go's networking packages import the macOS CoreFoundation framework for x509 roots: https://github.com/golang/go/tree/master/src/crypto/x509/internal/macos

main.go:

package main

// #include <stdio.h>
//
// void hello() { printf("Hello world\n"); }
import "C"

import "net/http"

func main() {
    C.hello()
    http.ListenAndServe(":8080", nil)
}

zcc:

#!/usr/bin/env bash
ZIG_LOCAL_CACHE_DIR="$HOME/tmp" zig cc -target x86_64-macos $@

zxx:

#!/usr/bin/env bash
ZIG_LOCAL_CACHE_DIR="$HOME/tmp" zig c++ -target x86_64-macos $@
$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC='zcc' CXX='zxx' go build -o test ./main.go 

Expected Behavior

Cross-compiled binary for x86_64-macos

Actual Behavior

# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running zcc failed: exit status 1
warning: unsupported linker arg: -headerpad
warning: unsupported linker arg: 1144
warning: unsupported linker arg: -no_pie
warning: unsupported linker arg: -pagezero_size
warning: unsupported linker arg: 4000000
warning: unsupported linker arg: --compress-debug-sections
warning: unsupported linker arg: zlib-gnu
warning(link): framework not found for '-framework CoreFoundation'
warning(link): framework not found for '-framework Security'
warning(link): Framework search paths:
error(link): undefined reference to symbol '_SecTrustSettingsCopyTrustSettings'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_SecTrustSettingsCopyCertificates'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_SecPolicyCopyProperties'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_SecItemExport'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFStringCreateWithBytes'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFRelease'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFNumberGetValue'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFEqual'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFDictionaryGetValueIfPresent'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFDataGetLength'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFDataGetBytePtr'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFArrayGetCount'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error(link): undefined reference to symbol '_CFArrayGetValueAtIndex'
error(link):   first referenced in '/tmp/go-link-87708621/go.o'
error: UndefinedSymbolReference

It's not possible to workaround this by providing the relevant framework files, either, because the Go linker expects xcrun to be available:

$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC='zcc' CXX='zxx' go build -ldflags='-extldflags=-F/home/slimsag/Desktop/sdk-macos-12.0/root/System/Library/Frameworks' -o test ./main.go
warning: unsupported linker arg: -headerpad
warning: unsupported linker arg: 1144
warning: unsupported linker arg: -no_pie
warning: unsupported linker arg: -pagezero_size
warning: unsupported linker arg: 4000000
warning: unsupported linker arg: --compress-debug-sections
warning: unsupported linker arg: zlib-gnu
/usr/local/go/pkg/tool/linux_amd64/link: /usr/local/go/pkg/tool/linux_amd64/link: running dsymutil failed: exec: "xcrun": executable file not found in $PATH
@slimsag slimsag added the bug Observed behavior contradicts documented or intended behavior label Mar 3, 2022
@slimsag slimsag changed the title Cannot cross compile Go HTTP server from Linux -> macOS Cannot cross compile Go HTTP server + CGO code from Linux -> macOS Mar 3, 2022
@slimsag
Copy link
Sponsor Contributor Author

slimsag commented Mar 4, 2022

Duplicate of #1349

@slimsag slimsag closed this as completed Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant