Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Docker build environment gets an upgrade!

This thread is locked; no one can reply to it. rss feed Print
Docker build environment gets an upgrade!
amarillion
Member #940
January 2001
avatar

Hey,

For the past few years I've been maintaining docker build environments for allegro. These docker containers have all the dependencies needed to build a typical allegro game.

With docker installed, a typical build would look like this:

docker run \
  -v `pwd`:/data \
  amarillion/alleg5-buildenv \
  make

This will download the latest docker image amarillion/alleg5-buildenv, volume-mount the current directory inside this docker image, and run make.

Apart from the linux variant, since the release of allegro 5.2.7, I've added a few variants, so now we have:

  • linux variant. Standard ubuntu-based build environment, with Release, Debug, Static and Monolith builds installed.

  • allegro 4 variants. For compiling older games on linux.

  • mingw-w64 variant. For cross-compiling windows binaries. Targets the i686 architecture (i.e. 32 bit). If desired, I could also whip up a variant for x86-64. Release, Debug, Static and Monolith all included. At the moment, I've omitted a few of the deps that I don't use much myself, like theora and physfs, but I can add them if desired.

  • d-lang variant. Includes D-lang tools (dmd) and SiegeLord's DAllegro5.

  • I've been working on android and emscripten variants, but these are still a work-in-progress. A raspberry PI variant is not out of the question either.

You can find all of these on dockerhub here: https://hub.docker.com/u/amarillion
Sources and some documentation is here: https://github.com/amarillion/allegro-buildenv/

So what can you do with this? Quite a lot...

  • Build a windows game from your linux machine. Using the mingw-w64 variant, you can have a working cross compilation toolchain up in a single command. No need to figure out how to cross-build all the dependencies of allegro, because I already did that for you!

  • Build a linux game from your windows/mac machine. Wait, what??? Yes that's right! In the past years, Docker Desktop for Windows has gone from a weird hack to a reliable technology (we use it all the time at my day job). So that means you can easily build a linux version of your allegro game without having to maintain a linux setup.

  • Continuous integration servers. This is how I use these myself. I have a little Jenkins-CI server at home, that monitors all my projects, and builds several variants every time I push a change. With the new mingw-w64 setup, I can now build both linux and windows variants from the same jenkins server. Since both github and gitlab now provide CI pipelines that use docker under the hood, potentially you can make it work for any open source project hosted on those sites.

  • Documenting how to build allegro. Dockerfiles contain all the precise steps needed to get Allegro compiling, starting from a pristine environment. If you want to know how to cross-compile allegro on mingw-w64, the best starting point is to follow the steps here: https://github.com/amarillion/allegro-buildenv/blob/master/alleg5-mingw/Dockerfile

  • Testing allegro builds. Docker containers are cordoned off from the rest of your OS, so you can quickly test a variation of your allegro dependency chain in isolation, without screwing with your development setup. I've been experimenting with emscripten this way (still WIP at this point)

I'd really love some feedback. Would you use it? Have you tried it? Does it work for you? What would you like to see added? What sort of documentation would you need?

See also the original announcement a few years back: https://www.allegro.cc/forums/thread/616906/

Mark Oates
Member #1,146
March 2001
avatar

Build a windows game from your linux machine. Using the mingw-w64 variant, you can have a working cross compilation toolchain up in a single command. No need to figure out how to cross-build all the dependencies of allegro, because I already did that for you!

A-mazing.

Quote:

Would you use it?

Absolutely. It'll take a while for me to get to it, but I've been trying to put something like this together myself for a long while. Right now, it's git push on mac, git pull on win, make, but I want it to all be completely automated, tests included. I'm looking forward to using this. My dream is to build this as a web service.

Niunio
Member #1,975
March 2002
avatar

Nice. I wonder if I can do the same thing for Allegro.pas, but I'm always busy :'(

-----------------
Current projects: Allegro.pas | MinGRo

Matthew Leverton
Supreme Loser
January 1999
avatar

Is this intended to build your own games?

e.g. A directory containing:

  • Makefile (my makefile with instructions on how to build my game with -lallegro)

  • main.c (my source code)

Then run docker from that directory?

amarillion
Member #940
January 2001
avatar

Is this intended to build your own games?

e.g. A directory containing:

Makefile (my makefile with instructions on how to build my game with -lallegro)

main.c (my source code)

Then run docker from that directory?

Yes indeed, that's the primary use case. To make it clearer, I've created a minimal example, containing just a makefile, a single source file, and a script to collect DLLs.

It should be possible to compile this example for windows and linux, using only docker. No need to set up any build tools or even allegro (You'd still want at least one toolchain during development, of course. But you don't need it here). So far I've only tested it on a linux host, but it should be possible on Mac/Windows hosts as well.

You can find the example here: https://github.com/amarillion/allegro-buildenv-example

Niunio said:

I wonder if I can do the same thing for Allegro.pas, but I'm always busy

If you can explain in a few simple bash commands how to set up Allegro.pas on Ubuntu (i.e. install Pascal, wget bindings, compile bindings), I can set you up with a simple Dockerfile. Then you can take it from there.

My dream is to build this as a web service.

That would be cool indeed. The Unity game engine provides a similar service, so it would be cool to be able to match that. I believe it should be possible to do this using the (free) CI pipelines provided by github / gitlab too, but I still have to try that.

Matthew Leverton
Supreme Loser
January 1999
avatar

Two issues that could trip people up:

  • File permissions. I'm unable to use this without giving world write access to the current folder because docker is trying to write the file as user id 1000 (whatever that happens to be). I'm not a docker expert when it comes to running it as a tool like this, but I assume there's something else trivial that can be done to remedy this.


  • The include uses local path (#include "allegro5/allegro.h") whereas I traditionally am used to building it from a system path (<allegro5/allegro.h>).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

amarillion
Member #940
January 2001
avatar

File permissions. I'm unable to use this without giving world write access to the current folder because docker is trying to write the file as user id 1000 (whatever that happens to be). I'm not a docker expert when it comes to running it as a tool like this, but I assume there's something else trivial that can be done to remedy this.

Yes, this can be solved by specifying your uid, for example

docker run \
  -u `id -u`:`id -g` \
  -v `pwd`:/data \
  amarillion/alleg5-buildenv \
  make

I'll add a note to the documentation.

Quote:

The include uses local path (#include "allegro5/allegro.h") whereas I traditionally am used to building it from a system path (<allegro5/allegro.h>).

I'm not sure, is this actually a problem? I copied the code from one of the allegro examples, I believe it should work either way.

Could I use this to cross compile from Windows 10 to OSX / Apple / iOS / Linux?

Linux, yes for sure. But OSX / Apple / iOS is a different problem altogether, I have no idea if this is possible. Probably not.

Docker containers are basically tiny linux virtual machines(*). Compiling for windows relies on the pre-existing possibility to cross-compile for windows on linux hosts. Docker doesn't create this possibility out of thin air, it just makes it easier to set it up.

*) On linux they're process groups that are walled-off from the rest of the system. On Mac / Windows, they really are implemented as a small virtual machine.

GullRaDriel
Member #3,861
September 2003
avatar

I may be wrong but I think it is doable even for windows, as there are official windows docker images hosted by microsoft docker (https://hub.docker.com/_/microsoft-windows-base-os-images)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

amarillion
Member #940
January 2001
avatar

If I understand correctly, the windows base images only work on windows. It's really a very different technology, a case of microsoft having linux envy. It's not really much help for me.

GullRaDriel
Member #3,861
September 2003
avatar

Yeah, after reading it you're right. As the docker image will have to use underlying host system calls, one need a windows host to run windows images.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

amarillion
Member #940
January 2001
avatar

Yeah I just did a quick proof on my linux machine:

docker run mcr.microsoft.com/windows/servercore:ltsc2019
ltsc2019: Pulling from windows/servercore
docker: no matching manifest for linux/amd64 in the manifest list entries.
See 'docker run --help'.

Best to stick to linux, it's the greatest common divisor.

As for cross-compiling mac from linux, there is a project called "darling", a bit like WINE but for Macs. Who knows, this could be useful here?

https://stackoverflow.com/questions/39409082/cross-compiling-for-os-x-from-linux
https://github.com/darlinghq/darling

Go to: