Skip to content

Commit

Permalink
Merge pull request #137 from rake-compiler/multiplat
Browse files Browse the repository at this point in the history
Allow using multiplatform images
  • Loading branch information
larskanis authored Dec 31, 2024
2 parents cc37afb + 26eaa65 commit aa27315
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Dockerfile.mri.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ ENV BASH_ENV=/etc/rubybashrc
##
<% if platform =~ /x64-mingw-ucrt/ %>
COPY --from=larskanis/mingw64-ucrt:20.04 \
/build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_amd64.deb \
/build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \
/build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \
/build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \
/build/mingw-w64-common_7.0.0-2_all.deb \
/build/mingw-w64-x86-64-dev_7.0.0-2_all.deb \
/build/binutils-mingw-w64-x86-64_*.deb \
/build/g++-mingw-w64-x86-64_*.deb \
/build/gcc-mingw-w64-base_*.deb \
/build/gcc-mingw-w64-x86-64_*.deb \
/build/mingw-w64-common_*.deb \
/build/mingw-w64-x86-64-dev_*.deb \
/debs/
RUN dpkg -i /debs/*.deb

Expand All @@ -57,6 +57,7 @@ if platform =~ /darwin/ %> clang python lzma-dev libxml2-dev libssl-d
if platform =~ /aarch64-linux-gnu/ %> gcc-aarch64-linux-gnu g++-aarch64-linux-gnu <% end %><%
if platform =~ /arm-linux-gnu/ %> gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf <% end %><%
if platform =~ /x86-linux-gnu/ %> gcc-i686-linux-gnu g++-i686-linux-gnu <% end %><%
if platform =~ /x86_64-linux-gnu/ %> gcc-x86-64-linux-gnu g++-x86-64-linux-gnu <% end %><%
if platform =~ /x86-mingw32/ %> gcc-mingw-w64-i686 g++-mingw-w64-i686 <% end %><%
if platform =~ /x64-mingw32/ %> gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 <% end %> && \
rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -148,7 +149,7 @@ RUN bash -c " \
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby.so | xargs rm
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby-static.a | while read f ; do cp $f `echo $f | sed s/-static//` ; done
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby.a | while read f ; do ar t $f | xargs ar d $f ; done
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name mkmf.rb | while read f ; do sed -i ':a;N;$!ba;s/TRY_LINK = [^\n]*\n[^\n]*\n[^\n]*LOCAL_LIBS)/& -lruby-static -lpthread -lrt -ldl <% if platform =~ /x86_64/ %> -lcrypt <% if platform !~ /musl/ %> -lz <% end %> <% end %>/' $f ; done
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name mkmf.rb | while read f ; do sed -i ':a;N;$!ba;s/TRY_LINK = [^\n]*\n[^\n]*\n[^\n]*LOCAL_LIBS)/& -lruby-static -lpthread -lrt -ldl/' $f ; done
<% end %>

<% if platform =~ /mingw/ %>
Expand Down
2 changes: 1 addition & 1 deletion build/mk_osxcross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set -x
curl -L -o MacOSX11.1.sdk.tar.xz https://github.com/larskanis/MacOSX-SDKs/releases/download/11.1/MacOSX11.1.sdk.tar.xz
tar -xf MacOSX11.1.sdk.tar.xz -C .
cp -rf /usr/lib/llvm-10/include/c++ MacOSX11.1.sdk/usr/include/c++
cp -rf /usr/include/x86_64-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits
cp -rf /usr/include/*-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits
tar -cJf MacOSX11.1.sdk.tar.xz MacOSX11.1.sdk

set +x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ diff --git a/tasks/bin/cross-ruby.rake b/tasks/bin/cross-ruby.rake
index 8317a2a3..8ed21718 100644
--- a/tasks/bin/cross-ruby.rake
+++ b/tasks/bin/cross-ruby.rake
@@ -116,11 +116,27 @@
@@ -116,11 +116,30 @@
"--host=#{mingw_host}",
"--target=#{mingw_target}",
"--build=#{RUBY_BUILD}",
- '--enable-shared',
+ '--enable-install-static-library',
+ '--disable-jit-support',
+ 'ac_cv_lib_z_uncompress=no',
+ 'ac_cv_lib_crypt_crypt=no',
+ 'ac_cv_func_crypt_r=no',
'--disable-install-doc',
'--with-ext=',
]
Expand Down
6 changes: 5 additions & 1 deletion mingw64-ucrt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN cd mingw-w64-* && \

# Install UCRT enabled deb-packages
RUN dpkg -i mingw-w64-common_7.0.0-2_all.deb \
mingw-w64-tools_7.0.0-2_amd64.deb \
mingw-w64-tools_7.0.0-2_*.deb \
mingw-w64-x86-64-dev_7.0.0-2_all.deb

# Download gcc-binutils sources for mingw
Expand All @@ -52,6 +52,10 @@ RUN apt-get source gcc-mingw-w64 && \
cd gcc-mingw-w64-* && \
mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y --no-install-recommends"

# Add version based alias
RUN ln -s `which autoconf` `which autoconf`2.69 && \
ln -s `which autom4te` `which autom4te`2.69

# Build gcc (only C and C++) based on UCRT headers and crt
ADD gcc-mingw-w64-*.patch ./
RUN cd gcc-mingw-w64-* && \
Expand Down
58 changes: 58 additions & 0 deletions mingw64-ucrt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Docker image with compilers for ruby platform x64-mingw-ucrt
------------------

This Dockerfile builds compilers for Windows UCRT target.
It takes the mingw compiler provided by Debian/Ubuntu and configures and compiles them for UCRT.
Outputs are *.deb files of binutils, gcc and g++.
Rake-compiler-dock reads them from this image as part of its build process for the x64-mingw-ucrt platform.

The image is provided for arm64 and amd64 architectures.
They are built by the following command:

```sh
docker buildx build . -t larskanis/mingw64-ucrt:20.04 --platform linux/arm64,linux/amd64 --push
```


Create builder instance for two architectures
------------------

Building with qemu emulation fails currently with a segfault, so that it must be built by a builder instance with at least one remote node for the other architecture.
Building on native hardware is also much faster (~30 minutes) than on qemu.
A two-nodes builder requires obviously a ARM and a Intel/AMD device.
It can be created like this:

```sh
# Make sure the remote instance can be connected
$ docker -H ssh://isa info

# Create a new builder with the local instance
$ docker buildx create --name isayoga

# Add the remote instance
$ docker buildx create --name isayoga --append ssh://isa

# They are inactive from the start
$ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
isayoga docker-container
\_ isayoga0 \_ unix:///var/run/docker.sock inactive
\_ isayoga1 \_ ssh://isa inactive
default* docker
\_ default \_ default running v0.13.2 linux/arm64

# Bootstrap the instances
$ docker buildx inspect --bootstrap --builder isayoga

# Set the new builder as default
$ docker buildx use isayoga

# Now it should be default and in state "running"
$ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
isayoga* docker-container
\_ isayoga0 \_ unix:///var/run/docker.sock running v0.18.2 linux/arm64
\_ isayoga1 \_ ssh://isa running v0.18.2 linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386
default docker
\_ default \_ default running v0.13.2 linux/arm64
```

0 comments on commit aa27315

Please sign in to comment.