Giter Site home page Giter Site logo

Comments (13)

zimmski avatar zimmski commented on July 23, 2024 1

Unfortunately I do not know how Docker works so I have (currently) no idea on how to implement this. But I do understand that the docker approach is more superior in terms of user-friendliness. Since the only steps for a complete cross-compile setup are just installing Docker, your Docker images and xgo. Giving my experience on doing cross-compile setups manually I find xgo's simplicity amazing!
So my current idea wish would be that xgo supports the following features:

  • choice of architectures
  • distinction between setting up xgo and building e.g. "xgo setup" and "xgo build"
  • choice for compiling remote/local package/file
  • support for some of "go"'s building parameters like "-v" "-race" "-ccflags" ...
  • prefix argument for the name of the resulting binaries
  • support for different Go versions (e.g. what happens when there is a new Go version?)

I am eager to help implementing (in two weeks i will have more time since i am relocating ๐Ÿ‘ ) but as mentioned I currently do not possess the necessary Docker knowledge.

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Yes, you're right. I haven't had personally the need for this, hence why I didn't add it. Although it shouldn't be too hard, it's not trivial either as you'll need a mechanism to upload code into the container.

Simply specifying a path and expecting xgo to figure out if it's a local private path or a remote public on isn't really doable, but I guess I could introduce an extra flag to signal a path to import into the container before compilation. So in the end, compiling your code could look something like:

xgo -lib path/to/private/package path/to/package/to/compile

where the two could obviously be the same.

[Ok, I could implement a mechanism to pick the local version of some package and only go remote if not available locally, but that's a tad overkill and will quickly introduce quirks, bugs and whatnot that the current always-remote-clone cannot have since it always uses virgin states).

Anyway, I'll think about this a bit and get back to the issue. In the mean time, if you have a particular idea on how you think this would be useful, or how you imagine it doable, do share :)

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Most of these seem reasonable requests so I'll just turn your wish list into a checklist to be able and check them off one by one eventually :) I myself will also be unavailable until the end of next week, so I guess most of these will have to wait till then, but I'll see if I have enough time to address one or two.

Docker is really cool but it has quite some quirks, so you do have to jump through some hoops to get everything going (e.g. you can't stream the stdout of docker through your own program (hence why I needed the extra docker pull step for my container).

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Blah... ok, I have the whole thing working for different Go releases, just can't convince docker to automatically build them with the correct dependencies. Their build service is very very limited. I'll try and look around to see if I can do it properly without needing to go down their suggested path (separate repo for every single dockerfile).

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Ok, after a long battle with docker, versioned containers work :) Although for now only Go 1.3.0 is supported, adding additional ones are trivial and I also introduced two wildcard versions: "1.3.x" matching the latest point release and "latest" matching the latest major release of Go.

These can be configured via the -go flag.

xgo -go 1.3.x github.com/project-iris/iris

from xgo.

zimmski avatar zimmski commented on July 23, 2024

Just in time for 1.3.1 :-)

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Added support for output prefixing through -out, and also supporting -v and -race now :) See README for more.

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Btw, I've talked to Dave Cheney about his arm packages for 1.3.1, and he said that maybe during the weekend he'll do it, so I'll be able to support the next Go release too afterwards.

from xgo.

kdar avatar kdar commented on July 23, 2024

@zimmski I made a fork and implemented what you were requesting. It doesn't build single files, but it builds local packages (a local package can just contain main.go, in your case).

Get it here: https://github.com/kdar/xgo/tree/localpkg

If looks for a "." or "/" at the beginning of the path to determine if it's a local package. So you can do xgo ./ or something similar.

Example:

cd $GOPATH/src
mkdir test
echo -e 'package main\n import "fmt"\n func main(){\nfmt.Println("Hello")\n}' > main.go
xgo -out "build/test" ./

This works with karalabe's dockerfiles. The only downside is it will error when copying files because the directories overlap (but it works fine regardless of the error displayed). This can be remedied if we modify the Dockerfiles as well to support this.

from xgo.

zimmski avatar zimmski commented on July 23, 2024

I am sorry to tell you guys that I switched to https://github.com/mitchellh/gox for new projects some time ago. But @kdar I will definitely will try your changes with the next cgo-dependent project!

from xgo.

bdesham avatar bdesham commented on July 23, 2024

@kdar This is excellent, thank you!

Your example instructions are missing a cd commandโ€ฆ in case it will save someone else a couple of seconds, the instructions should be

cd $GOPATH/src
mkdir test
cd test
echo -e 'package main\n import "fmt"\n func main(){\nfmt.Println("Hello")\n}' > main.go
xgo -out "build/test" ./

from xgo.

karalabe avatar karalabe commented on July 23, 2024

Had been doing some work lately requiring xgo, so I've added a lot of new features, including building local code. If instead of the import path you specify a local path (begins in either . or /), it will resolve the import path, mount in all source code found in the various GOPATH components and cross compile using all code found on the host machine. Also, it will mount every local folder as read only to ensure that no modifications are made to your local files.

The idea is based on @kdar's code, so I thank him for that, though it needed a bit of rework to enable read only filesystems and multiple GOPATH components. Hope it's useful :)

from xgo.

jjhesk avatar jjhesk commented on July 23, 2024

@karalabe do you have some examples to show me? im using 1.11.2

from xgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.