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

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

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

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

calmh opened this issue Sep 12, 2013 · 2 comments

Comments

@calmh
Copy link
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
Copy link
Contributor Author

calmh commented Sep 12, 2013

Comment 1:

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

@minux
Copy link
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.

yudai added a commit to yudai/gotty that referenced this issue Aug 23, 2015
`os/user.Current()` is not available on Darwin when a binary is cross
compiled from another platform.
See also: golang/go#6376
tsenart pushed a commit to mesosphere/mesos-dns that referenced this issue Sep 23, 2015
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
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
user.Current() relies on cgo (well os/user does) and thus is not cross compilable
See golang/go#6376
andreaskoch added a commit to andreaskoch/allmark that referenced this issue Nov 17, 2015
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 /issues/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
Use environment for determining user per golang/go#6376
diwakergupta pushed a commit to dropbox/dbxcli that referenced this issue Mar 11, 2016
This causes issues with cross-compilation due to
golang/go#6376

Use https://github.com/mitchellh/go-homedir instead.
@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.
Projects
None yet
Development

No branches or pull requests

3 participants