user.Current panic in darwin-amd64 when crosscompiled from linux-amd64 #6376

Closed
calmh opened this Issue Sep 12, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@calmh
Contributor

calmh commented Sep 12, 2013

Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What steps will reproduce the problem?

Compile and run http://play.golang.org/p/fI0-SKcrXR

This works as expected (i.e. prints current user details) on both linux-amd64 and
darwin-amd64. However, when using the cross compilation instructions at
http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go to build
a darwin-amd64 binary from linux-amd64 it does not. Both environments running go 1.1.2
built from source.

What is the expected output?

jb@jborg-mbp:~ $ ./homedir-built-locally
&{502 20 jb Jakob Borg /Users/jb} <nil>

What do you see instead?

jb@jborg-mbp:~ $ ./homedir-crosscompiled-in-linux
<nil> user: Current not implemented on darwin/amd64

Which compiler are you using (5g, 6g, 8g, gccgo)?

8g

Which operating system are you using?

Linux, Mac OS X

Which version are you using?  (run 'go version')

b@ps-build1:~ % go version
go version go1.1.2 linux/amd64
@calmh

This comment has been minimized.

Show comment
Hide comment
@calmh

calmh Sep 12, 2013

Contributor

Comment 1:

Eh. "panic" should of course be "returns error". There is no panic.
Contributor

calmh commented Sep 12, 2013

Comment 1:

Eh. "panic" should of course be "returns error". There is no panic.
@minux

This comment has been minimized.

Show comment
Hide comment
@minux

minux Sep 12, 2013

Member

Comment 2:

os/user relies on cgo, and cgo is disabled for cross compiling,
thus this is expected.
if you use os/user, you must compile natively on OS X.
even if we enable cross compilation cgo support, I doubt everybody have
a working OS X cross toolchain on their linux machine.

Status changed to WorkingAsIntended.

Member

minux commented Sep 12, 2013

Comment 2:

os/user relies on cgo, and cgo is disabled for cross compiling,
thus this is expected.
if you use os/user, you must compile natively on OS X.
even if we enable cross compilation cgo support, I doubt everybody have
a working OS X cross toolchain on their linux machine.

Status changed to WorkingAsIntended.

@copumpkin copumpkin referenced this issue in AdRoll/hologram Mar 27, 2015

Closed

user.Current issue with new build process #32

@techtonik techtonik referenced this issue in lxc/lxd Aug 22, 2015

Closed

Packaging for Fedora 22 #830

yudai added a commit to yudai/gotty that referenced this issue Aug 23, 2015

Replace `user.Current()` with `os.Getenv("HOME")`
`os/user.Current()` is not available on Darwin when a binary is cross
compiled from another platform.
See also: golang/go#6376

@wkentaro wkentaro referenced this issue in getantibody/antibody Aug 31, 2015

Closed

panic: user: Current not implemented on linux/amd64 #61

@tsenart tsenart referenced this issue in mesosphere/mesos-dns Sep 23, 2015

Closed

Error (Current not implemented on linux/amd64) #275

tsenart added a commit to mesosphere/mesos-dns that referenced this issue Sep 23, 2015

records: Find user's home directory through env
As reported in golang/go#6376,
`os/user.Current` doesn't work with cross-compilation.
This commit replaces its use with `os.Getenv` of the `$HOME` and
`$USERPROFILE` environment variables.

Fixes #275

@tsenart tsenart referenced this issue in mesosphere/mesos-dns Sep 23, 2015

Merged

records: Find user's home directory through env #277

ebartels added a commit to ebartels/hdfs that referenced this issue Oct 2, 2015

hlidotbe added a commit to epicagency/deploybot-cli that referenced this issue Oct 3, 2015

Replaced `user.Current()` by `os.Getenv("HOME")`
user.Current() relies on cgo (well os/user does) and thus is not cross compilable
See golang/go#6376

@dmp42 dmp42 referenced this issue in docker/machine Oct 15, 2015

Closed

Makefile is broken #1974

@andrewrynhard andrewrynhard referenced this issue in FooSoft/homemaker Nov 6, 2015

Closed

Cross compiled build not implemented? #6

@andreaskoch andreaskoch referenced this issue in andreaskoch/allmark Nov 16, 2015

Closed

Current binary doesn't work on OSX 10.11.1 #1

andreaskoch added a commit to andreaskoch/allmark that referenced this issue Nov 17, 2015

Detect the user's home directory without user.Current()
user.Current() fails on Mac OS for binaries that have been
cross-compiled on another OS than Mac with the message:
"Error: user: Current not implemented on darwin/amd64"

Since this is, for some reason unclear to me, intended
behaviour by go (see: golang/go#6376)
I will use Mitchell Hachimoto's go-homedir library for
determining the current users home directory path.

I also fixed two failing unit tests that are unrelated to
this feature.

Fixes issue andreaskoch/allmark#1

ebartels added a commit to ebartels/hdfs that referenced this issue Dec 21, 2015

colinmarc added a commit to colinmarc/hdfs that referenced this issue Jan 4, 2016

Merge pull request #18 from ebartels/master
Use environment for determining user per golang/go#6376

@darron darron referenced this issue in DataDog/kvexpress Jan 10, 2016

Closed

1.3 Bug #51

@avinashbot avinashbot referenced this issue in avinashbot/satellite Feb 8, 2016

Closed

Broken Linux Builds #6

diwakergupta added a commit to dropbox/dbxcli that referenced this issue Mar 11, 2016

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.