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

go_get with --arch=linux_x86 fails #584

Closed
katzdm opened this issue Apr 5, 2019 · 7 comments
Closed

go_get with --arch=linux_x86 fails #584

katzdm opened this issue Apr 5, 2019 · 7 comments

Comments

@katzdm
Copy link
Contributor

katzdm commented Apr 5, 2019

Given a go_get rule in package //third_party/go:

go_get(
    name = "ratelimit",
    get = "gopkg.in/bsm/ratelimit.v1",
)

Running plz build //third_party/go:ratelimit on MacOS will succeed. However, running:

plz build --arch=linux_x86 //third_party/go:ratelimit

will fail. This is because the expected ratelimit.v1.a artifact goes into {TMP_DIR}/pkg/linux_386/gopkg.in/bsm/ratelimit.v1, but plz expects to find the artifact in a linux_x86 directory. Consequently, running the same command with _386 architecture:

plz build --arch=linux_386 //third_party/go:ratelimit

will succeed.

@katzdm
Copy link
Contributor Author

katzdm commented Apr 10, 2019

Hey @peterebden - Thanks for addressing this one! Unfortunately, I believe there is a second, related issue. go_library targets don't seem to find libraries fetched by go_get, when cross-compiling with --arch=linux_x86. More precisely, if I create a target //my_lib to depend on the target from my original issue description, like:

go_library(
    name = "my_lib",
    srcs = ["my_lib.go"],
    deps = ["//third_party/go:ratelimit"],
)

Then this fails with plz build --arch=linux_x86 //my_lib:

Error building target ///linux_x86//my_lib:my_lib: exit status 1
my_lib/my_lib.go, line 9, column 2: can't find import: "gopkg.in/bsm/ratelimit.1/..."

Note that this continues to work, when compiling with --arch=linux_386. I assume this OS -> GOOS change probably needs to be made somewhere else, as well.

@peterebden
Copy link
Member

Ah yeah fair - hadn't gotten as far as testing that yet. I think you're probably right (and hopefully it is not hard).

@peterebden
Copy link
Member

FWIW f9129b4 should fix that error - but most libraries will fail by missing imports because we don't provide a cross-compiled stdlib for them. Would be nice to do that at some point but it's a bit more work than the fixes here :)

@katzdm
Copy link
Contributor Author

katzdm commented Apr 10, 2019

True, but you provided excellent guidance on http://plz.build for how to work around that, which I've already followed :-)

Go can produce that via something like GOOS="linux" GOARCH="386" go install -i std.

Worked like a charm.

@katzdm
Copy link
Contributor Author

katzdm commented Apr 10, 2019

@peterebden I think you might need to make the OS/GOOS+ARCH/GOARCH change in a few more places in this file - In particular, for the functions _go_library_cmds and _go_binary_cmds. I've tested this change in my local workspace, and it resolves the problem I've been running into - I've opened #591 to fix this.

There are additional uses of CONFIG.OS in go_test and cgo_library, but I'm not as familiar with those rules.

@peterebden
Copy link
Member

Ha nice, I should try that for testing I suppose :) Will circle back around to this one when I can!

@peterebden peterebden reopened this Apr 10, 2019
@katzdm
Copy link
Contributor Author

katzdm commented Apr 10, 2019

This is working now :-)

@katzdm katzdm closed this as completed Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants