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

Cross-Compilation (linux to MinGW 64) #509

Closed
wants to merge 1 commit into from

Conversation

s-ol
Copy link

@s-ol s-ol commented Dec 9, 2017

(This is WIP and for documenting progress so far)

I am running arch and installed these packages:

mingw-w64-binutils 2.29-1
mingw-w64-cmake 1-18
mingw-w64-crt 5.0.3-1
mingw-w64-gcc 7.2.0-1
mingw-w64-headers 5.0.3-1
mingw-w64-pkg-config 2-3
mingw-w64-winpthreads 5.0.3-1
mingw-w64-glew 2.1.0-1

Compiling deps:

  • can't get GLEW to work but seems to link against mingw-w64-glew package

  • rtaudio and rtmidi also fail in random ways

  • rest can be built using:

    make ARCH=win CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ LD=x86_64-w64-mingw32-ld CMAKE=x86_64-w64-mingw32-cmake CONFIGURE="./configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --enable-shared --enable-static"
    

(possibly needs PATH=/usr/x86_64-w64-mingw32/bin/:$PATH)

@s-ol
Copy link
Author

s-ol commented Dec 9, 2017

obviously not worrying about a clean makefile rn, just trying to get it to work at all first

@s-ol
Copy link
Author

s-ol commented Dec 9, 2017

libzip needs mingw-w64-zlib which has a broken PKGBUILD for arch; copied the CC=${_arch}-gcc line up above the ./configure command too to fix that (as mentioned in AUR comments).

@s-ol
Copy link
Author

s-ol commented Dec 9, 2017

Removed the AudioInterface and all MIDI modules and references in the code, as well as the rtmidi/rtaudio dependencies (just need -lRack to build plugins, which is my goal) for now. Plugin built, on to test....?

@AndrewBelt could we have a separate libRack target that doesn't require the Rt* dependencies? Or is there already something like this that I didn't get from the Makefile?

@s-ol
Copy link
Author

s-ol commented Dec 9, 2017

Cross compiled .dll works with downloaded Rack!

@Miserlou
Copy link

Miserlou commented Dec 9, 2017

Hey @s-ol - this is excellent work.

What I'd really love is if we could make a Docker image so that anybody can easily and automatically cross compile for different architectures. Any chance you'd be able to make a Docker image for your work?

@s-ol
Copy link
Author

s-ol commented Dec 11, 2017

@Miserlou working on it. IMO docker images are a bit overhyped for this kind of thing but the Dockerfile will be a good reference anyway and since some CI can run in an image directly there's some validity there.

@Miserlou
Copy link

Nice! Yeah, Docker is overhyped but this is a good use case. I'm mostly interested in this for building a build CI for modules, not for Rack itself - related: VCVRack/library#6

@s-ol
Copy link
Author

s-ol commented Dec 11, 2017

my god, this was a pain but I finally got glew and glfw to compile cleanly both. Before it was a hack where it was using the headers from the included source and the binary from my arch install, which was hard to reproduce. I think i finally have it building clean from this branch with:

export CC=x86_64-w64-mingw32-gcc
export CXX=x86_64-w64-mingw32-g++
export LD=x86_64-w64-mingw32-ld
export AR=x86_64-w64-mingw32-ar
export CMAKE=x86_64-w64-mingw32-cmake
make SYSTEM=linux-mingw64 CFGFLAGS="--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --enable-shared --enable-static" WITHOUT_CORE=1 dep
make WITHOUT_CORE=1

and then plugins build just with make as well.
Required packages:

mingw-w64-binutils 2.29-1
mingw-w64-cmake 1-18
mingw-w64-gcc 7.2.0-1
mingw-w64-headers 5.0.3-1
mingw-w64-zlib 1.2.11-1
mingw-w64-crt 5.0.3-1
mingw-w64-pkg-config 2-3

@Miserlou
Copy link

Very nice! Do you want to try to Dockerize everything with cloning the right Rack release and multi-arch builds for plugins? :D

@s-ol s-ol changed the base branch from v0.5 to master December 11, 2017 20:28
@s-ol
Copy link
Author

s-ol commented Dec 11, 2017

@Miserlou it is dockerized from the Rack main directory. I don't think its feasible to develop one Dockerfile for multiarch publishing, it makes more sense to have separate ones because then the Rack dependencies can be preinstalled in the image, not built at (docker-)runtime.

I have just managed to cross-compile Rack (minus the core modules) in docker for the first time. Here's my Dockerfile:

FROM base/devel

RUN pacman -Sy --noconfirm sudo wget unzip
RUN useradd -m notroot && echo "notroot ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/notroot

ADD https://aur.archlinux.org/cgit/aur.git/snapshot/mingw-w64-pkg-config.tar.gz \
  https://aur.archlinux.org/cgit/aur.git/snapshot/mingw-w64-cmake.tar.gz \
  https://aur.archlinux.org/cgit/aur.git/snapshot/mingw-w64-zlib.tar.gz \
  /opt/packages/
RUN cd /opt/packages && for f in *.gz; do tar xf $f; done && chmod -R 777 *
RUN cd /opt/packages/mingw-w64-pkg-config && sudo -u notroot makepkg -si --noconfirm --force
RUN cd /opt/packages/mingw-w64-cmake && sudo -u notroot makepkg -si --noconfirm --force
RUN cd /opt/packages/mingw-w64-zlib && sudo -u notroot makepkg -si --noconfirm --force

COPY . /opt/Rack
WORKDIR /opt/Rack

ENV ARCH=win \
	CC=x86_64-w64-mingw32-gcc \
	LD=x86_64-w64-mingw32-ld \
	AR=x86_64-w64-mingw32-ar \
	CXX=x86_64-w64-mingw32-g++ \
	CFGFLAGS="--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --enable-shared --enable-static"

RUN make dep SYSTEM=linux-mingw64 CMAKE=x86_64-w64-mingw32-cmake WITHOUT_CORE=1
RUN make WITHOUT_CORE=1

VOLUME /opt/Rack/plugins/plugin
WORKDIR /opt/Rack/plugins/plugin
ENTRYPOINT ["make"]
CMD ["dist"]

I will push the image to s0lll0s/vcvrack-builder on dockerhub.
It should be able to be used like this:

$ docker run --rm -v $(pwd):/opt/Rack/plugins/plugin s0lll0s/vcvrack-builder dist VERSION=0.5.1

Unforunately i'm out of time for today, please do test and report back your findings.

I won't check in the Dockerfile to this branch because I don't believe it belongs into VCVRack's top level and otherwise this branch is clean and, IMO, strictly relevant for an actual merge (what do you think @AndrewBelt?).

@Miserlou
Copy link

Woho! Dang, this is huge. Will try to experiment with this ASAP.

@s-ol
Copy link
Author

s-ol commented Dec 11, 2017

@Miserlou hm, glew is breaking in the docker build still (means I can't push). Don't have any more time today but after spending the last two days on this I'll be damned if that's not solve-able.

@s-ol
Copy link
Author

s-ol commented Dec 12, 2017

so much for no more attempts but.... IT WORKS!

FROM base/devel

RUN pacman -Sy --noconfirm sudo wget zip unzip
RUN useradd -m notroot && echo "notroot ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/notroot

ADD https://aur.archlinux.org/cgit/aur.git/snapshot/mingw-w64-pkg-config.tar.gz \
	https://aur.archlinux.org/cgit/aur.git/snapshot/mingw-w64-cmake.tar.gz \
	https://aur.archlinux.org/cgit/aur.git/snapshot/mingw-w64-zlib.tar.gz \
	/opt/packages/
RUN cd /opt/packages && for f in *.gz; do tar xf $f; done && chmod -R 777 *
RUN cd /opt/packages/mingw-w64-pkg-config && sudo -u notroot makepkg -si --noconfirm --force
RUN cd /opt/packages/mingw-w64-cmake && sudo -u notroot makepkg -si --noconfirm --force
RUN cd /opt/packages/mingw-w64-zlib && sudo -u notroot makepkg -si --noconfirm --force

COPY . /opt/Rack
WORKDIR /opt/Rack

RUN make dep \
	ARCH=win \
	SYSTEM=linux-mingw64 \
	CC=x86_64-w64-mingw32-gcc \
	LD=x86_64-w64-mingw32-ld \
	AR=x86_64-w64-mingw32-ar \
	CXX=x86_64-w64-mingw32-g++ \
	CMAKE=x86_64-w64-mingw32-cmake \
	CFGFLAGS="--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --enable-shared --enable-static" \
	WITHOUT_CORE=1
RUN make \
	ARCH=win \
	LD=x86_64-w64-mingw32-ld \
	CC=x86_64-w64-mingw32-gcc \
	CXX=x86_64-w64-mingw32-g++ \
	WITHOUT_CORE=1

VOLUME /opt/Rack/plugins/plugin
WORKDIR /opt/Rack/plugins/plugin
ENTRYPOINT [ "make", \
	"ARCH=win", \
	"LD=x86_64-w64-mingw32-ld", \
	"CC=x86_64-w64-mingw32-gcc", \
	"CXX=x86_64-w64-mingw32-g++" \
]
CMD ["dist"]
$ docker run --rm -v `pwd`:/opt/Rack/plugins/plugin -u `id -u`:`id -g` s0lll0s/vcvrack-builder dist VERSION=0.5.1

The image is up too now.

@Miserlou
Copy link

Very nice!

It's working for me, and some of my files compile, but now I'm facing what might be a more annoying problem: code written for clang doesn't seem to want to compile for gcc. Any tips for writing cross-compiler, cross-platform code?

Awesome, awesome work - I bet this is going to save a lot of people a lot of effort, and hopefully mean that we get lots more modules for lots more platforms.

@s-ol
Copy link
Author

s-ol commented Dec 15, 2017

@Miserlou I don't have experience with that since I've been using gcc always. What exactly have you been having problems with? In the end you should theoretically stick to a C++ standard and then your code is supposed to be compiler-safe. Rack itself is c++11 so sticking to that would be a good idea.

@cschol cschol mentioned this pull request Apr 3, 2018
@dbradee
Copy link

dbradee commented Apr 5, 2018

Please excuse the possibly noobish question, but what does "dockerizing" VCV Rack or it's plugins buy us? To me Docker = Cloud, and VCV Rack (again, to me) is a desktop application. Thanks in advance for your reply!

@Miserlou
Copy link

Miserlou commented Apr 5, 2018

The application wouldn't run inside of Docker - we would just build a small Docker image (or images) with all of the necessary toolchains required to build a module on each of the target platforms, as getting this stuff installed and configured for every module developer is the hardest part, and the reason we don't have all modules for all platforms.

@s-ol
Copy link
Author

s-ol commented Apr 5, 2018

@dbradee exactly, as @Miserlou said we are dockerizing the/a build environment to gurantee easy setup of fresh builds.

Also note that docker is not really related to cloud things, it is simply a tool to sandbox processes in their own tiny operating sysstems and to describe those images/containers etc.

This comes in very handily when you want to run and maintain various different services (databases, webservers, ...) as in a cloud environment, but there are many valid use cases (such as this).

With some X11 trickery I'm pretty sure you can even run a GUI app like VCVRack from inside docker and have it render to your native desktop (why you would want to do this is a good question and is what i guess you were getting at originally)

@AndrewBelt
Copy link
Member

AndrewBelt commented Apr 6, 2018

With the Rack SDK at https://github.com/VCVRack/Rack/issues/258#issuecomment-376293898, all you need now is mingw. Download it and run

ARCH=win CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ STRIP=x86_64-w64-mingw32-strip make dist

to build your plugins. On Mac:

ARCH=mac CC=x86_64-apple-darwin15-clang CXX=x86_64-apple-darwin15-clang++ STRIP=x86_64-apple-darwin15-strip make dist

Surprisingly, building on Linux from Linux requires Docker because I can't figure out how to compile and link against glibc 2.23 on newer versions of GCC. Anyone want to research a way to do this?

@AndrewBelt AndrewBelt closed this May 19, 2018
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

Successfully merging this pull request may close these issues.

4 participants