From 0dbd8517e72fd23464c3d52af276260670f693ed Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sun, 13 Nov 2022 16:25:45 -0500 Subject: [PATCH 01/30] Provide linux/arm64 images for m1s --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d02f8b7..211097ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,9 @@ jobs: - arm-linux - aarch64-linux - jruby + docker-platform: + - linux/amd64 + - linux/arm64 runs-on: ubuntu-latest env: @@ -53,10 +56,13 @@ jobs: ruby-version: "3.0" bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Build docker image run: | docker buildx create --driver docker-container --use - bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" + bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="docker buildx build --platform ${{ inputs.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" - name: Move build cache and remove outdated layers run: | From e4672bd2e6c31495681e4b0edcd25a05dfdbe633 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Thu, 15 Dec 2022 23:50:03 -0500 Subject: [PATCH 02/30] Use matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2777a9ac..837d8e6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - name: Build docker image run: | docker buildx create --driver docker-container --use - bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="docker buildx build --platform ${{ inputs.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" + bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" - name: Move build cache and remove outdated layers run: | From 0b130a7e406a8034f8d12f03106bdc923d716e52 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 18:53:10 -0500 Subject: [PATCH 03/30] Translate docker platform to manylinux image slug --- .github/workflows/ci.yml | 2 +- Dockerfile.mri.erb | 8 +++++--- Rakefile | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 837d8e6a..4d41f527 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - name: Build docker image run: | docker buildx create --driver docker-container --use - bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" + bundle exec rake build:${PLATFORM} DOCKER_PLATFORM="${{ matrix.docker-platform }}" RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" - name: Move build cache and remove outdated layers run: | diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 25c68ee8..dcb93632 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -1,9 +1,11 @@ <% image = case platform - when /x86_64-linux/ then "quay.io/pypa/manylinux2014_x86_64" - when /x86-linux/ then "quay.io/pypa/manylinux2014_i686" - else "ubuntu:20.04" + when /x86_64-linux/, /x86-linux/ + manylinux_image + else + "ubuntu:20.04" end + manylinux = !!(image =~ /manylinux/) %> FROM <%= image %> diff --git a/Rakefile b/Rakefile index 6c46f47f..b59ad7ea 100644 --- a/Rakefile +++ b/Rakefile @@ -26,6 +26,28 @@ namespace :build do platforms.each do |platform, target| sdf = "Dockerfile.mri.#{platform}" + # Native images to alleviate qemu slowness, and manylinux2014 provides per-arch + # images. But they are not yet conformant to the Docker platform spec (i.e. + # amd64/linux). We have to do some string manipulation to get the right for + # now, but you should be able to nuke this code soon, and rely on only the + # buildx `--platform` feature instead.... + # + # See: https://github.com/pypa/manylinux/issues/1306 + cpu = case ENV["DOCKER_BUILD_PLATFORM"] + when /arm64/ + "aarch64" + when /amd64/ + "x86_64" + else + if ENV["CI"] + raise "Couldnt infer manylinux CPU for #{ENV["DOCKER_BUILD_PLATFORM"].inspect}" + else + "x86_64" + end + end + + manylinux_image = "quay.io/pypa/manylinux2014_#{cpu}" + desc "Build image for platform #{platform}" task platform => sdf task sdf do From a3e29549fdc67c00311efea3e4ee3959d5bd94c7 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 18:55:13 -0500 Subject: [PATCH 04/30] s/DOCKER_PLATFORM/DOCKER_BUILD_PLATFORM --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72ef7792..7014ab9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - name: Build docker image run: | docker buildx create --driver docker-container --use - bundle exec rake build:${PLATFORM} DOCKER_PLATFORM="${{ matrix.docker-platform }}" RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" + bundle exec rake build:${PLATFORM} DOCKER_BUILD_PLATFORM="${{ matrix.docker-platform }}" RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" - name: Move build cache and remove outdated layers run: | From d4857ff5a28192afe2df6111efdf9effe5d9e403 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 19:10:56 -0500 Subject: [PATCH 05/30] Remove all refs to specific dpkg archs --- Dockerfile.mri.erb | 8 ++++---- Rakefile | 10 +++++----- mingw64-ucrt/Dockerfile | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 664e1869..4b702ec5 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -80,10 +80,10 @@ USER root <% 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/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_<%= dpkg_arch %>.deb \ + /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ + /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ + /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ /build/mingw-w64-common_7.0.0-2_all.deb \ /build/mingw-w64-x86-64-dev_7.0.0-2_all.deb \ /debs/ diff --git a/Rakefile b/Rakefile index b59ad7ea..4674fadd 100644 --- a/Rakefile +++ b/Rakefile @@ -33,20 +33,20 @@ namespace :build do # buildx `--platform` feature instead.... # # See: https://github.com/pypa/manylinux/issues/1306 - cpu = case ENV["DOCKER_BUILD_PLATFORM"] + manylinux_cpu, dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] when /arm64/ - "aarch64" + ["aarch64", "arm64"] when /amd64/ - "x86_64" + ["x86_64", "amd64"] else if ENV["CI"] raise "Couldnt infer manylinux CPU for #{ENV["DOCKER_BUILD_PLATFORM"].inspect}" else - "x86_64" + ["x86_64", "amd64"] end end - manylinux_image = "quay.io/pypa/manylinux2014_#{cpu}" + manylinux_image = "quay.io/pypa/manylinux2014_#{manylinux_cpu}" desc "Build image for platform #{platform}" task platform => sdf diff --git a/mingw64-ucrt/Dockerfile b/mingw64-ucrt/Dockerfile index eb07f5ab..60333c42 100644 --- a/mingw64-ucrt/Dockerfile +++ b/mingw64-ucrt/Dockerfile @@ -1,3 +1,4 @@ + FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive @@ -32,7 +33,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_$(dpkg --print-architecture).deb \ mingw-w64-x86-64-dev_7.0.0-2_all.deb # Download gcc-binutils sources for mingw From 7bf3aa52e25b0719dc9d3c871eb923f472c5350e Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 19:24:59 -0500 Subject: [PATCH 06/30] Prepare mingw32-ucrt before build --- Rakefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rakefile b/Rakefile index 4674fadd..6650ae09 100644 --- a/Rakefile +++ b/Rakefile @@ -84,6 +84,8 @@ namespace :prepare do end end +task "build:mingw64-ucrt" => "prepare:mingw64-ucrt" + desc "Run tests" task :test do sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v" From 079d0cb41010c39b7a14e34dbbf19fb38590e657 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 19:56:12 -0500 Subject: [PATCH 07/30] Sorry 32bit, later --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7014ab9c..f3117c39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - x86-mingw32 - x64-mingw-ucrt - x64-mingw32 - - x86-linux + # - x86-linux - x86_64-linux - x86_64-darwin - arm64-darwin From 67b3e1211506be28084a7d0fe00464385322f516 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 22:14:49 -0500 Subject: [PATCH 08/30] More dkpg stuff --- Dockerfile.mri.erb | 10 +++++----- Rakefile | 9 +++++---- mingw64-ucrt/Dockerfile | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 4b702ec5..5cfe1999 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -80,10 +80,10 @@ USER root <% if platform=~/x64-mingw-ucrt/ %> COPY --from=larskanis/mingw64-ucrt:20.04 \ - /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_<%= dpkg_arch %>.deb \ - /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ - /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ - /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ + /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_$(dpkg --print-architecture).deb \ + /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_$(dpkg --print-architecture).deb \ + /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_$(dpkg --print-architecture).deb \ + /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_$(dpkg --print-architecture).deb \ /build/mingw-w64-common_7.0.0-2_all.deb \ /build/mingw-w64-x86-64-dev_7.0.0-2_all.deb \ /debs/ @@ -117,7 +117,7 @@ RUN git clone -q --depth=1 https://github.com/tpoechtrager/osxcross.git /opt/osx 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/$(dpkg --print-architecture)-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ tar -cJf MacOSX11.1.sdk.tar.xz MacOSX11.1.sdk && \ cd /opt/osxcross && \ UNATTENDED=1 SDK_VERSION=11.1 OSX_VERSION_MIN=10.13 USE_CLANG_AS=1 ./build.sh && \ diff --git a/Rakefile b/Rakefile index 6650ae09..866c1e0a 100644 --- a/Rakefile +++ b/Rakefile @@ -33,16 +33,16 @@ namespace :build do # buildx `--platform` feature instead.... # # See: https://github.com/pypa/manylinux/issues/1306 - manylinux_cpu, dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] + manylinux_cpu = case ENV["DOCKER_BUILD_PLATFORM"] when /arm64/ - ["aarch64", "arm64"] + "aarch64" when /amd64/ - ["x86_64", "amd64"] + "x86_64" else if ENV["CI"] raise "Couldnt infer manylinux CPU for #{ENV["DOCKER_BUILD_PLATFORM"].inspect}" else - ["x86_64", "amd64"] + "x86_64" end end @@ -68,6 +68,7 @@ namespace :build do RakeCompilerDock::ParallelDockerBuild.new(platforms.map{|pl, _| "Dockerfile.mri.#{pl}" } + ["Dockerfile.jruby"], workdir: "tmp/docker", docker_build_cmd: docker_build_cmd) desc "Build images for all MRI platforms in parallel" + rry multitask :mri => platforms.map(&:first) desc "Build images for all platforms in parallel" diff --git a/mingw64-ucrt/Dockerfile b/mingw64-ucrt/Dockerfile index 60333c42..c14f52c1 100644 --- a/mingw64-ucrt/Dockerfile +++ b/mingw64-ucrt/Dockerfile @@ -34,7 +34,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_$(dpkg --print-architecture).deb \ - mingw-w64-x86-64-dev_7.0.0-2_all.deb + mingw-w64-$(dpkg --print-architecture)-dev_7.0.0-2_all.deb # Download gcc-binutils sources for mingw RUN apt-get source binutils-mingw-w64 && \ From a51486e6d4a90d280441a68e32e79439f3f363a6 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 22:19:05 -0500 Subject: [PATCH 09/30] Fix typo --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 866c1e0a..cd7986ce 100644 --- a/Rakefile +++ b/Rakefile @@ -68,7 +68,6 @@ namespace :build do RakeCompilerDock::ParallelDockerBuild.new(platforms.map{|pl, _| "Dockerfile.mri.#{pl}" } + ["Dockerfile.jruby"], workdir: "tmp/docker", docker_build_cmd: docker_build_cmd) desc "Build images for all MRI platforms in parallel" - rry multitask :mri => platforms.map(&:first) desc "Build images for all platforms in parallel" From 0403fe63fb8fb4d5f42a9b7706919f0351462d26 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 22:32:14 -0500 Subject: [PATCH 10/30] Erbify --- Dockerfile.mri.erb | 10 +++++----- Rakefile | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 5cfe1999..1ce52150 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -80,10 +80,10 @@ USER root <% if platform=~/x64-mingw-ucrt/ %> COPY --from=larskanis/mingw64-ucrt:20.04 \ - /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_$(dpkg --print-architecture).deb \ - /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_$(dpkg --print-architecture).deb \ - /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_$(dpkg --print-architecture).deb \ - /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_$(dpkg --print-architecture).deb \ + /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_<%= dpkg_arch %>.deb \ + /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ + /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ + /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ /build/mingw-w64-common_7.0.0-2_all.deb \ /build/mingw-w64-x86-64-dev_7.0.0-2_all.deb \ /debs/ @@ -117,7 +117,7 @@ RUN git clone -q --depth=1 https://github.com/tpoechtrager/osxcross.git /opt/osx 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/$(dpkg --print-architecture)-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ + cp -rf /usr/include/<%= dpkg_arch %>-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ tar -cJf MacOSX11.1.sdk.tar.xz MacOSX11.1.sdk && \ cd /opt/osxcross && \ UNATTENDED=1 SDK_VERSION=11.1 OSX_VERSION_MIN=10.13 USE_CLANG_AS=1 ./build.sh && \ diff --git a/Rakefile b/Rakefile index cd7986ce..6650ae09 100644 --- a/Rakefile +++ b/Rakefile @@ -33,16 +33,16 @@ namespace :build do # buildx `--platform` feature instead.... # # See: https://github.com/pypa/manylinux/issues/1306 - manylinux_cpu = case ENV["DOCKER_BUILD_PLATFORM"] + manylinux_cpu, dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] when /arm64/ - "aarch64" + ["aarch64", "arm64"] when /amd64/ - "x86_64" + ["x86_64", "amd64"] else if ENV["CI"] raise "Couldnt infer manylinux CPU for #{ENV["DOCKER_BUILD_PLATFORM"].inspect}" else - "x86_64" + ["x86_64", "amd64"] end end From 19be52a9e5327a86d3136b72fa42240fd2f1ed16 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 16 Dec 2022 22:39:04 -0500 Subject: [PATCH 11/30] So many aliases --- Dockerfile.mri.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 1ce52150..8c1b1e78 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -117,7 +117,7 @@ RUN git clone -q --depth=1 https://github.com/tpoechtrager/osxcross.git /opt/osx 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/<%= dpkg_arch %>-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ + cp -rf /usr/include/<%= manylinux_cpu %>-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ tar -cJf MacOSX11.1.sdk.tar.xz MacOSX11.1.sdk && \ cd /opt/osxcross && \ UNATTENDED=1 SDK_VERSION=11.1 OSX_VERSION_MIN=10.13 USE_CLANG_AS=1 ./build.sh && \ From b8c3992c2150f90a061c456377d3baa3a4369a33 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 00:53:18 -0500 Subject: [PATCH 12/30] Use x86-64 mingw deb pkg always --- mingw64-ucrt/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mingw64-ucrt/Dockerfile b/mingw64-ucrt/Dockerfile index c14f52c1..60333c42 100644 --- a/mingw64-ucrt/Dockerfile +++ b/mingw64-ucrt/Dockerfile @@ -34,7 +34,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_$(dpkg --print-architecture).deb \ - mingw-w64-$(dpkg --print-architecture)-dev_7.0.0-2_all.deb + mingw-w64-x86-64-dev_7.0.0-2_all.deb # Download gcc-binutils sources for mingw RUN apt-get source binutils-mingw-w64 && \ From 8a26e1308f64b87bd697a39a542e9073c1aa5a66 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 01:22:47 -0500 Subject: [PATCH 13/30] [linux/arm64] Add tests to the matrix for docker platform --- .github/workflows/ci.yml | 59 +++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3117c39..9c8d5f26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,22 +35,25 @@ jobs: - arm-linux - aarch64-linux - jruby - docker-platform: - - linux/amd64 - - linux/arm64 + docker-platform-cpu: + - amd64 + - arm64 runs-on: ubuntu-latest env: PLATFORM: ${{ matrix.platform }} + DOCKER_BUILD_PLATFORM: linux/${{ matrix.docker-platform-cpu }} steps: - uses: actions/checkout@v2 - name: Cache Docker layers - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: tmp/build-cache - key: ${{ runner.os }}-${{ matrix.platform }}-buildx-${{ github.sha }} + key: ${{ runner.os }}-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-buildx-${{ github.sha }} + # TODO: remove last key restore-keys: | + ${{ runner.os }}-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-buildx ${{ runner.os }}-${{ matrix.platform }}-buildx - uses: ruby/setup-ruby@v1 @@ -62,9 +65,26 @@ jobs: uses: docker/setup-qemu-action@v2 - name: Build docker image + id: buildx run: | docker buildx create --driver docker-container --use - bundle exec rake build:${PLATFORM} DOCKER_BUILD_PLATFORM="${{ matrix.docker-platform }}" RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load" + extra_tag="rcd-${PLATFORM}-${DOCKER_BUILD_PLATFORM}-${{ github.sha }}" + docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" + bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" + + # Save the image if the commit message contains the docker platform name (e.g. "[linux/arm64] ...") + if [[ "${{ github.event.head_commit.message }}" == *"[$DOCKER_BUILD_PLATFORM]"* ]]; then + echo "::info::Saving docker image $extra_tag" + docker save -o "tmp/${extra_tag}.tar" $extra_tag + echo "image-tarball: tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT + fi + + - name: Upload Docker image tarball + if: ${{ steps.buildx.outputs.image-tarball != '' }} + uses: actions/upload-artifact@v3 + with: + path: ${{ steps.buildx.outputs.image-tarball }} + retention-days: 1 - name: Move build cache and remove outdated layers run: | @@ -83,7 +103,7 @@ jobs: - name: Upload binary gem uses: actions/upload-artifact@v2 with: - name: gem-${{ matrix.platform }} + name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} path: test/rcd_test/pkg/*-*-*.gem - if: matrix.platform == 'jruby' @@ -109,11 +129,11 @@ jobs: name: Upload static binary gem uses: actions/upload-artifact@v2 with: - name: gem-${{ matrix.platform }}-static + name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static path: test/rcd_test/pkg/*-*-*.gem job_test_native: - name: Test (${{matrix.ruby}}, ${{matrix.platform}}) + name: Test (${{matrix.ruby}}, ${{matrix.platform}}, ${{ matrix.docker-platform-cpu }}) needs: docker_build strategy: fail-fast: false @@ -155,11 +175,11 @@ jobs: with: ruby-version: ${{ matrix.ruby }} - run: ruby --version - - name: Download gem-${{matrix.platform}} + - name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} uses: actions/download-artifact@v2 with: - name: gem-${{ matrix.platform }} - - name: Install gem-${{matrix.platform}} + name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} + - name: Install gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} run: gem install --local *.gem --verbose - name: Run tests run: | @@ -199,11 +219,11 @@ jobs: with: ruby-version: ${{ matrix.ruby }} - run: ruby --version - - name: Download gem-${{matrix.platform}}-static + - name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static uses: actions/download-artifact@v2 with: - name: gem-${{ matrix.platform }}-static - - name: Install gem-${{matrix.platform}}-static + name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static + - name: Install gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static run: gem install --local *.gem --verbose - name: Run tests run: | @@ -237,12 +257,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Download gem-${{matrix.platform}} + - name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} uses: actions/download-artifact@v2 with: - name: gem-${{ matrix.platform }} + name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} - name: Build image and Run tests run: | + docker buildx create --driver docker-container --use docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker build --rm --build-arg from_image=${{matrix.from_image}} -t ruby-test -f test/env/Dockerfile.${{matrix.dockerfile}} . - docker run --rm -t --network=host -v `pwd`:/build ruby-test + docker buildx build --platform=$DOCKER_BUILD_PLATFORM --rm --build-arg from_image=${{matrix.from_image}} -t ruby-test -f test/env/Dockerfile.${{matrix.dockerfile}} . + docker run --platform=$DOCKER_BUILD_PLATFORM --rm -t --network=host -v `pwd`:/build ruby-test From 1c0461bd98a28b6048490f20f7caf53356aa6948 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 01:32:59 -0500 Subject: [PATCH 14/30] [linux/arm64] [linux/amd64] Get the slash out of the extra tag --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c8d5f26..5f46bb75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,7 @@ jobs: id: buildx run: | docker buildx create --driver docker-container --use - extra_tag="rcd-${PLATFORM}-${DOCKER_BUILD_PLATFORM}-${{ github.sha }}" + extra_tag="rcd-${PLATFORM}-${{ matrix.docker-platform-cpu }}-${{ github.sha }}" docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" From d56306f908f830e4bd4d699f5aa89f130bd98d9d Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 01:38:36 -0500 Subject: [PATCH 15/30] [linux/arm64] [linux/amd64] Use correct ref to commit message --- .github/workflows/ci.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f46bb75..1df34f5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: PLATFORM: ${{ matrix.platform }} DOCKER_BUILD_PLATFORM: linux/${{ matrix.docker-platform-cpu }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache Docker layers uses: actions/cache@v3 @@ -72,11 +72,10 @@ jobs: docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" - # Save the image if the commit message contains the docker platform name (e.g. "[linux/arm64] ...") - if [[ "${{ github.event.head_commit.message }}" == *"[$DOCKER_BUILD_PLATFORM]"* ]]; then + if [[ "$(git log -1 --pretty=format:"%s")" =~ *"$DOCKER_BUILD_PLATFORM"* ]]; then echo "::info::Saving docker image $extra_tag" docker save -o "tmp/${extra_tag}.tar" $extra_tag - echo "image-tarball: tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT + echo "image-tarball=tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT fi - name: Upload Docker image tarball @@ -170,7 +169,7 @@ jobs: runs-on: ${{ matrix.os }}-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} @@ -214,7 +213,7 @@ jobs: runs-on: ${{ matrix.os }}-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} @@ -256,7 +255,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }} uses: actions/download-artifact@v2 with: From d572b34d561631ee259d9c2e5430141bc6ab10e0 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 02:06:38 -0500 Subject: [PATCH 16/30] [linux/arm64] [linux/amd64] Use correct ref to commit message --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1df34f5e..53a003c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" - if [[ "$(git log -1 --pretty=format:"%s")" =~ *"$DOCKER_BUILD_PLATFORM"* ]]; then + if [[ "$(git log -1 --pretty=format:"%s")" =~ *"${{ matrix.docker-platform-cpu }}"* ]]; then echo "::info::Saving docker image $extra_tag" docker save -o "tmp/${extra_tag}.tar" $extra_tag echo "image-tarball=tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT From 581c626ca257637167c0f3a7d4cb61a2c278c49c Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 02:15:34 -0500 Subject: [PATCH 17/30] [linux/arm64] [linux/amd64] Use correct ref to commit message --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53a003c8..8ef6ae28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,11 +72,11 @@ jobs: docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" - if [[ "$(git log -1 --pretty=format:"%s")" =~ *"${{ matrix.docker-platform-cpu }}"* ]]; then + # if [[ "$(git log -1 --pretty=format:"%s")" =~ *"${{ matrix.docker-platform-cpu }}"* ]]; then echo "::info::Saving docker image $extra_tag" docker save -o "tmp/${extra_tag}.tar" $extra_tag echo "image-tarball=tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT - fi + # fi - name: Upload Docker image tarball if: ${{ steps.buildx.outputs.image-tarball != '' }} From 63e23dd44aeef43ccbd2e4653cad93c438afbcb7 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 13:14:15 -0500 Subject: [PATCH 18/30] [linux/arm64] Try fix upload container via commit --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ef6ae28..25f96c18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,16 +72,17 @@ jobs: docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" - # if [[ "$(git log -1 --pretty=format:"%s")" =~ *"${{ matrix.docker-platform-cpu }}"* ]]; then + if [[ "${{ contains(github.event.head_commit.message, matrix.docker-platform-cpu) }}" == "true" ]]; then echo "::info::Saving docker image $extra_tag" docker save -o "tmp/${extra_tag}.tar" $extra_tag echo "image-tarball=tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT - # fi + fi - name: Upload Docker image tarball if: ${{ steps.buildx.outputs.image-tarball != '' }} uses: actions/upload-artifact@v3 with: + name: docker-save-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-${{ github.sha }} path: ${{ steps.buildx.outputs.image-tarball }} retention-days: 1 From 191fdcb23ef0fdcc0b8446fafcf42ab8efa0d78c Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 14:09:30 -0500 Subject: [PATCH 19/30] [linux/arm64] Use own platform manifests --- .github/workflows/ci.yml | 7 + Dockerfile.mri.erb | 2 +- Dockerfile.mri.x64-mingw-ucrt | 172 +++++++++++++++++++ Rakefile | 29 ++-- script/remanifest-manylinux-multiplatform.sh | 32 ++++ 5 files changed, 226 insertions(+), 16 deletions(-) create mode 100644 Dockerfile.mri.x64-mingw-ucrt create mode 100755 script/remanifest-manylinux-multiplatform.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25f96c18..55da228e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,9 +67,16 @@ jobs: - name: Build docker image id: buildx run: | + echo "::group::Preparing docker build" docker buildx create --driver docker-container --use extra_tag="rcd-${PLATFORM}-${{ matrix.docker-platform-cpu }}-${{ github.sha }}" docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag" + if bundle exec rake -T | grep -q "prepare:${PLATFORM}"; then + echo "::info::Preparing docker image for ${PLATFORM}" + bundle exec rake prepare:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" + fi + echo "::endgroup::" + bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build" if [[ "${{ contains(github.event.head_commit.message, matrix.docker-platform-cpu) }}" == "true" ]]; then diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 8c1b1e78..b7a2974d 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -117,7 +117,7 @@ RUN git clone -q --depth=1 https://github.com/tpoechtrager/osxcross.git /opt/osx 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/<%= manylinux_cpu %>-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ + cp -rf /usr/include/"$(uname -m)"-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits && \ tar -cJf MacOSX11.1.sdk.tar.xz MacOSX11.1.sdk && \ cd /opt/osxcross && \ UNATTENDED=1 SDK_VERSION=11.1 OSX_VERSION_MIN=10.13 USE_CLANG_AS=1 ./build.sh && \ diff --git a/Dockerfile.mri.x64-mingw-ucrt b/Dockerfile.mri.x64-mingw-ucrt new file mode 100644 index 00000000..88e412dc --- /dev/null +++ b/Dockerfile.mri.x64-mingw-ucrt @@ -0,0 +1,172 @@ +FROM ubuntu:20.04 +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get -y update && \ + apt-get install -y curl git-core xz-utils build-essential zlib1g-dev libreadline-dev libssl-dev wget unzip sudo gnupg2 dirmngr cmake pkg-config autoconf && \ + rm -rf /var/lib/apt/lists/* + +# Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000 +RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm + +# Make sure rvm and later settings are available in interactive and non-interactive shells +RUN echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc && \ + echo "source /etc/rubybashrc" >> /etc/bashrc && \ + echo "source /etc/rubybashrc" >> /etc/bash.bashrc +ENV BASH_ENV /etc/rubybashrc + +USER rvm + +RUN mkdir ~/.gnupg && \ + chmod 700 ~/.gnupg && \ + echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf + +# install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts +RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \ + (curl -L http://get.rvm.io | sudo bash) && \ + bash -c " \ + source /etc/rubybashrc && \ + rvm autolibs disable && \ + rvmsudo rvm cleanup all " + +# Import patch files for ruby and gems +COPY build/patches /home/rvm/patches/ + +# install rubies and fix permissions on +ENV RVM_RUBIES 2.5.9 3.1.0 +RUN bash -c " \ + export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \ + for v in ${RVM_RUBIES} ; do \ + rvm install \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \ + done && \ + rvm cleanup all && \ + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " + +# Install rake-compiler and typical gems in all Rubies +# do not generate documentation for gems +# TODO: stop pinning rubygems to 3.3.20 once https://github.com/rake-compiler/rake-compiler/pull/209 is merged +RUN echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \ + bash -c " \ + rvm all do gem update --system=3.3.20 --no-document && \ + rvm all do gem install --no-document bundler 'bundler:~>1.16' 'rake-compiler:1.1.6' hoe mini_portile rubygems-tasks mini_portile2 && \ + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " + +# Install rake-compiler's cross rubies in global dir instead of /root +RUN sudo mkdir -p /usr/local/rake-compiler && \ + sudo chown rvm.rvm /usr/local/rake-compiler && \ + ln -s /usr/local/rake-compiler ~/.rake-compiler + +# Add cross compilers for Windows and Linux +USER root + +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 \ + /debs/ +RUN dpkg -i /debs/*.deb + + +RUN bash -c " \ + rvm alias create default 3.1.0 && \ + rvm use default " + + + +# Patch rake-compiler to build and install static libraries for Linux rubies +USER rvm +COPY build/patches2 /home/rvm/patches/ +RUN bash -c " \ + for v in ${RVM_RUBIES} ; do \ + cd /usr/local/rvm/gems/ruby-\$v/gems/rake-compiler-1.1.6 && \ + echo applying patches to ruby-\$v /home/rvm/patches/rake-compiler-1.1.6/*.patch && \ + ( git apply /home/rvm/patches/rake-compiler-1.1.6/*.patch || true ) \ + done " + +# Patch rubies for cross build +#USER root +#RUN bash -c " \ +# for v in 2.7.0 3.0.0 3.1.0 ; do \ +# curl -SL http://cache.ruby-lang.org/pub/ruby/\${v:0:3}/ruby-\$v.tar.xz | tar -xJC /root/ && \ +# cd /root/ruby-\$v && \ +# git apply /home/rvm/patches/ruby-\$v/*.patch && \ +# cd .. && \ +# mkdir -p /usr/local/rake-compiler/sources/ && \ +# tar cjf /usr/local/rake-compiler/sources/ruby-\$v.tar.bz2 ruby-\$v && \ +# chown rvm /usr/local/rake-compiler -R && \ +# rm -rf /root/ruby-\$v ; \ +# done " +#USER rvm + +ENV XRUBIES 3.2.0-rc1 +# Build xruby versions in parallel +# Then cleanup all build artifacts +RUN bash -c " \ + rvm use 3.1.0 && \ + export CPPFLAGS='-D__USE_MINGW_ANSI_STDIO=1' && \ + export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong -s' && \ + export LDFLAGS='-pipe -s' && \ + export LIBS='-l:libssp.a' && \ + \ + export MAKE='make V=1 -j`nproc`' && \ + rake-compiler cross-ruby VERSION=$XRUBIES HOST=x86_64-w64-mingw32 && \ + rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \ + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " +ENV XRUBIES 3.1.0 +# Build xruby versions in parallel +# Then cleanup all build artifacts +RUN bash -c " \ + rvm use 3.1.0 && \ + export CPPFLAGS='-D__USE_MINGW_ANSI_STDIO=1' && \ + export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong -s' && \ + export LDFLAGS='-pipe -s' && \ + export LIBS='-l:libssp.a' && \ + \ + export MAKE='make V=1 -j`nproc`' && \ + rake-compiler cross-ruby VERSION=$XRUBIES HOST=x86_64-w64-mingw32 && \ + rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \ + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " + + +# RubyInstaller doesn't install libgcc -> link it static. +RUN find /usr/local/rake-compiler/ruby/*mingw*/ -name rbconfig.rb | while read f ; do sed -i 's/."LDFLAGS". = "/&-static-libgcc /' $f ; done +# Raise Windows-API to Vista (affects ruby < 2.6 only) +RUN find /usr/local/rake-compiler/ruby -name rbconfig.rb | while read f ; do sed -i 's/0x0501/0x0600/' $f ; done +# Don't link to static libruby +RUN find /usr/local/rake-compiler/ruby -name lib*-ruby*.dll.a | while read f ; do n=`echo $f | sed s/.dll//` ; mv $f $n ; done + +USER root + +# Fix paths in rake-compiler/config.yml +RUN sed -i -- "s:/root/.rake-compiler:/usr/local/rake-compiler:g" /usr/local/rake-compiler/config.yml + + +# Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker. +COPY build/strip_wrapper /root/ +RUN mv /usr/bin/x86_64-w64-mingw32-strip /usr/bin/x86_64-w64-mingw32-strip.bin && \ + ln /root/strip_wrapper /usr/bin/x86_64-w64-mingw32-strip + +# Use posix pthread for mingw so that C++ standard library for thread could be +# available such as std::thread, std::mutex, so on. +# https://sourceware.org/pthreads-win32/ +RUN printf "1\n" | update-alternatives --config x86_64-w64-mingw32-gcc && \ + printf "1\n" | update-alternatives --config x86_64-w64-mingw32-g++ + + + +# Install SIGINT forwarder +COPY build/sigfw.c /root/ +RUN gcc $HOME/sigfw.c -o /usr/bin/sigfw + +# Install user mapper +COPY build/runas /usr/bin/ +COPY build/rcd-env.sh /etc/profile.d/ +RUN echo "source /etc/profile.d/rcd-env.sh" >> /etc/rubybashrc + +# Install sudoers configuration +COPY build/sudoers /etc/sudoers.d/rake-compiler-dock + +ENV RUBY_CC_VERSION 3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0:2.4.0 + +CMD bash diff --git a/Rakefile b/Rakefile index 6650ae09..8e91de85 100644 --- a/Rakefile +++ b/Rakefile @@ -26,27 +26,28 @@ namespace :build do platforms.each do |platform, target| sdf = "Dockerfile.mri.#{platform}" - # Native images to alleviate qemu slowness, and manylinux2014 provides per-arch - # images. But they are not yet conformant to the Docker platform spec (i.e. - # amd64/linux). We have to do some string manipulation to get the right for - # now, but you should be able to nuke this code soon, and rely on only the - # buildx `--platform` feature instead.... - # - # See: https://github.com/pypa/manylinux/issues/1306 - manylinux_cpu, dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] + dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] when /arm64/ - ["aarch64", "arm64"] + "arm64" when /amd64/ - ["x86_64", "amd64"] + "amd64" else if ENV["CI"] - raise "Couldnt infer manylinux CPU for #{ENV["DOCKER_BUILD_PLATFORM"].inspect}" + raise "Couldnt infer dpkg arch for #{ENV["DOCKER_BUILD_PLATFORM"].inspect}" else - ["x86_64", "amd64"] + "amd64" end end - manylinux_image = "quay.io/pypa/manylinux2014_#{manylinux_cpu}" + # Native images to alleviate qemu slowness, and manylinux2014 provides per-arch + # images. But they are not yet conformant to the Docker platform spec (i.e. + # amd64/linux). We generate our own platformed manifests now (using + # scrip/remanifest-manylinux-multiplatform.sh), but you should be able to + # nuke that code soon, and rely on only the buildx `--platform` feature once + # manylinux finishes the feature. + # + # See: https://github.com/pypa/manylinux/issues/1306 + manylinux_image = "rbsys/manylinux2014:2022-12-11-145d107" desc "Build image for platform #{platform}" task platform => sdf @@ -84,8 +85,6 @@ namespace :prepare do end end -task "build:mingw64-ucrt" => "prepare:mingw64-ucrt" - desc "Run tests" task :test do sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v" diff --git a/script/remanifest-manylinux-multiplatform.sh b/script/remanifest-manylinux-multiplatform.sh new file mode 100755 index 00000000..0e228679 --- /dev/null +++ b/script/remanifest-manylinux-multiplatform.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +# A script to build and push a multi-arch image to Docker Hub, based on +# https://github.com/pypa/manylinux/issues/1306 + +repo="${DOCKERHUB_USER:-larskanis}" +tags=("latest" "2022-12-11-145d107") +base_images=("manylinux2014" "manylinux_2_24") + +for base_image in "${base_images[@]}"; do + for tag in "${tags[@]}"; do + echo Re-manifesting "$base_image":"$tag" >&2 + + docker pull --quiet quay.io/pypa/"$base_image"_aarch64:"$tag" + docker pull --quiet quay.io/pypa/"$base_image"_x86_64:"$tag" + + docker tag quay.io/pypa/"$base_image"_x86_64:"$tag" "$repo"/"$base_image"_x86_64:"$tag" + docker tag quay.io/pypa/"$base_image"_aarch64:"$tag" "$repo"/"$base_image"_aarch64:"$tag" + + docker push --quiet "$repo"/"$base_image"_x86_64:"$tag" + docker push --quiet "$repo"/"$base_image"_aarch64:"$tag" + + docker manifest create "$repo"/"$base_image":"$tag" \ + --amend "$repo"/"$base_image"_x86_64:"$tag" \ + --amend "$repo"/"$base_image"_aarch64:"$tag" + + docker manifest push "$repo"/"$base_image":"$tag" + done +done From d2f3e6042a7dc37c4ec633f72861fbe429b6a011 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 14:16:06 -0500 Subject: [PATCH 20/30] [linux/arm64] Adjust mk_osxcross to reference generic archdir --- build/mk_osxcross.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/mk_osxcross.sh b/build/mk_osxcross.sh index 410b84eb..82aa97a3 100755 --- a/build/mk_osxcross.sh +++ b/build/mk_osxcross.sh @@ -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"$(uname -m)"-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 From 2558eb81454e6f93dd99e1f9809e6a21a14fda55 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 14:50:50 -0500 Subject: [PATCH 21/30] [linux/arm64] Host vs foreign arch --- Dockerfile.mri.erb | 15 +++++++++------ Rakefile | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 1613a319..5350b51f 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -23,8 +23,10 @@ RUN rm -f /usr/local/bin/sudo && \ echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers <% else %> ENV DEBIAN_FRONTEND noninteractive -RUN apt-get -y update && \ - apt-get install -y sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr zlib1g-dev libreadline-dev libsqlite0-dev libssl-dev libyaml-dev libffi-dev && \ +RUN dpkg --add-architecture <%= foreign_dpkg_arch %> && \ + apt-get -y update && \ + apt-get install -y sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr && \ + apt-get install -y zlib1g-dev:<%= foreign_dpkg_arch %> libreadline-dev:<%= foreign_dpkg_arch %> libsqlite0-dev:<%= foreign_dpkg_arch %> libssl-dev:<%= foreign_dpkg_arch %> libyaml-dev:<%= foreign_dpkg_arch %> libffi-dev:<%= foreign_dpkg_arch %> && \ rm -rf /var/lib/apt/lists/* <% end %> @@ -76,10 +78,10 @@ USER root <% if platform=~/x64-mingw-ucrt/ %> COPY --from=larskanis/mingw64-ucrt:20.04 \ - /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_<%= dpkg_arch %>.deb \ - /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ - /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ - /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= dpkg_arch %>.deb \ + /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_<%= host_dpkg_arch %>.deb \ + /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= host_dpkg_arch %>.deb \ + /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= host_dpkg_arch %>.deb \ + /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_<%= host_dpkg_arch %>.deb \ /build/mingw-w64-common_7.0.0-2_all.deb \ /build/mingw-w64-x86-64-dev_7.0.0-2_all.deb \ /debs/ @@ -90,6 +92,7 @@ RUN apt-get -y update && \ apt-get install -y <% if platform=~/darwin/ %> clang python lzma-dev libxml2-dev libssl-dev libc++-10-dev <% end %><% if platform=~/aarch64-linux/ %> gcc-aarch64-linux-gnu g++-aarch64-linux-gnu <% end %><% +if platform=~/x86_64-linux/ %> gcc-x86-64-linux-gnu g++-x86-64-linux-gnu <% end %><% if platform=~/arm-linux/ %> gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf <% 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 %> && \ diff --git a/Rakefile b/Rakefile index 8e91de85..e5b15172 100644 --- a/Rakefile +++ b/Rakefile @@ -10,23 +10,23 @@ DOCKERHUB_USER = ENV['DOCKERHUB_USER'] || "larskanis" docker_build_cmd = Shellwords.split(ENV['RCD_DOCKER_BUILD'] || "docker build") platforms = [ - ["x86-mingw32", "i686-w64-mingw32"], - ["x64-mingw32", "x86_64-w64-mingw32"], - ["x64-mingw-ucrt", "x86_64-w64-mingw32"], - ["x86-linux", "i686-redhat-linux"], - ["x86_64-linux", "x86_64-redhat-linux"], - ["x86_64-darwin", "x86_64-apple-darwin"], - ["arm64-darwin", "aarch64-apple-darwin"], - ["arm-linux", "arm-linux-gnueabihf"], - ["aarch64-linux", "aarch64-linux-gnu"], + ["x86-mingw32", "i686-w64-mingw32", "i386"], + ["x64-mingw32", "x86_64-w64-mingw32", "amd64"], + ["x64-mingw-ucrt", "x86_64-w64-mingw32", "amd64"], + ["x86-linux", "i686-redhat-linux", "i386"], + ["x86_64-linux", "x86_64-redhat-linux", "amd64"], + ["x86_64-darwin", "x86_64-apple-darwin", "amd64"], + ["arm64-darwin", "aarch64-apple-darwin", "arm64"], + ["arm-linux", "arm-linux-gnueabihf", "armhf"], + ["aarch64-linux", "aarch64-linux-gnu", "arm64"], ] namespace :build do - platforms.each do |platform, target| + platforms.each do |platform, target, foreign_dpkg_arch| sdf = "Dockerfile.mri.#{platform}" - dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] + host_dpkg_arch = case ENV["DOCKER_BUILD_PLATFORM"] when /arm64/ "arm64" when /amd64/ From 034db51b65d380a85f694e89232dca5ccd9ed4e9 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 16:08:08 -0500 Subject: [PATCH 22/30] [linux/arm64] Use debian multiarch, dunno how to do manylinux.... --- Dockerfile.mri.erb | 13 +++---- build/mk_osxcross.sh | 2 +- build/setup_dpkg_multiarch_for_target.sh | 43 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100755 build/setup_dpkg_multiarch_for_target.sh diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index 5350b51f..db82e689 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -23,11 +23,13 @@ RUN rm -f /usr/local/bin/sudo && \ echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers <% else %> ENV DEBIAN_FRONTEND noninteractive -RUN dpkg --add-architecture <%= foreign_dpkg_arch %> && \ - apt-get -y update && \ - apt-get install -y sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr && \ - apt-get install -y zlib1g-dev:<%= foreign_dpkg_arch %> libreadline-dev:<%= foreign_dpkg_arch %> libsqlite0-dev:<%= foreign_dpkg_arch %> libssl-dev:<%= foreign_dpkg_arch %> libyaml-dev:<%= foreign_dpkg_arch %> libffi-dev:<%= foreign_dpkg_arch %> && \ - rm -rf /var/lib/apt/lists/* +COPY ./build/setup_dpkg_multiarch_for_target.sh / +RUN /setup_dpkg_multiarch_for_target.sh <%= foreign_dpkg_arch %>; + +RUN apt-get -y -qq update && \ + apt-get -y -qq install sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr && \ + apt-get -y -qq install zlib1g-dev:<%= foreign_dpkg_arch %> libreadline-dev:<%= foreign_dpkg_arch %> libsqlite0-dev:<%= foreign_dpkg_arch %> libssl-dev:<%= foreign_dpkg_arch %> libyaml-dev:<%= foreign_dpkg_arch %> libffi-dev:<%= foreign_dpkg_arch %> && \ + rm -rf /var/lib/apt/lists/*; <% end %> # Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000 @@ -92,7 +94,6 @@ RUN apt-get -y update && \ apt-get install -y <% if platform=~/darwin/ %> clang python lzma-dev libxml2-dev libssl-dev libc++-10-dev <% end %><% if platform=~/aarch64-linux/ %> gcc-aarch64-linux-gnu g++-aarch64-linux-gnu <% end %><% -if platform=~/x86_64-linux/ %> gcc-x86-64-linux-gnu g++-x86-64-linux-gnu <% end %><% if platform=~/arm-linux/ %> gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf <% 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 %> && \ diff --git a/build/mk_osxcross.sh b/build/mk_osxcross.sh index 82aa97a3..af7ec630 100755 --- a/build/mk_osxcross.sh +++ b/build/mk_osxcross.sh @@ -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"$(uname -m)"-linux-gnu/c++/9/bits/ MacOSX11.1.sdk/usr/include/c++/v1/bits +cp -rf /usr/include/"$(uname -m)"-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 diff --git a/build/setup_dpkg_multiarch_for_target.sh b/build/setup_dpkg_multiarch_for_target.sh new file mode 100755 index 00000000..657899cf --- /dev/null +++ b/build/setup_dpkg_multiarch_for_target.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -exuo pipefail +IFS=$'\n\t' + +main() { + local to_uninstall=() + + if ! command -v dpkg-architecture; then + echo "dpkg-architecture not found, installing" >&2 + apt-get -qq -y update + apt-get -qq -y install --no-install-recommends debhelper lsb-release + rm -rf /var/lib/apt/lists/* + to_uninstall+=("debhelper" "lsb-release") + fi + + deb_host_arch="$(dpkg-architecture --query DEB_HOST_ARCH)" + deb_target_arch="$1" + + if [ "$deb_target_arch" != "$deb_host_arch" ]; then + echo "Setting up multiarch support for $deb_target_arch" >&2 + + # Add arch support for target so we can install libs + dpkg --add-architecture "$deb_target_arch" + # Qualify our current source lists to make sure debian doesn't infer stuff + sed -i "s/^deb http/deb [arch=$deb_host_arch] http/" /etc/apt/sources.list + # Add sources for ported target libs + sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main universe restricted multiverse\" >> /etc/apt/sources.list" + sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main universe restricted multiverse\" >> /etc/apt/sources.list" + sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-security main universe restricted multiverse\" >> /etc/apt/sources.list" + apt-get update + else + echo "No need to set up multiarch support for $deb_target_arch" + fi + + if [ "${#to_uninstall[@]}" -gt 0 ]; then + apt-get remove -y "${to_uninstall[@]}" + fi + + rm "$0" +} + +main "$@" From fbe2f2077a4d6bfd695b5820a22ad347d8644583 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 16:31:28 -0500 Subject: [PATCH 23/30] [linux/arm64] Cleanup multiarch stuff --- Dockerfile.mri.x64-mingw-ucrt | 172 ----------------------- build/setup_dpkg_multiarch_for_target.sh | 25 +--- 2 files changed, 2 insertions(+), 195 deletions(-) delete mode 100644 Dockerfile.mri.x64-mingw-ucrt diff --git a/Dockerfile.mri.x64-mingw-ucrt b/Dockerfile.mri.x64-mingw-ucrt deleted file mode 100644 index 88e412dc..00000000 --- a/Dockerfile.mri.x64-mingw-ucrt +++ /dev/null @@ -1,172 +0,0 @@ -FROM ubuntu:20.04 -ENV DEBIAN_FRONTEND noninteractive -RUN apt-get -y update && \ - apt-get install -y curl git-core xz-utils build-essential zlib1g-dev libreadline-dev libssl-dev wget unzip sudo gnupg2 dirmngr cmake pkg-config autoconf && \ - rm -rf /var/lib/apt/lists/* - -# Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000 -RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm - -# Make sure rvm and later settings are available in interactive and non-interactive shells -RUN echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc && \ - echo "source /etc/rubybashrc" >> /etc/bashrc && \ - echo "source /etc/rubybashrc" >> /etc/bash.bashrc -ENV BASH_ENV /etc/rubybashrc - -USER rvm - -RUN mkdir ~/.gnupg && \ - chmod 700 ~/.gnupg && \ - echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf - -# install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts -RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \ - (curl -L http://get.rvm.io | sudo bash) && \ - bash -c " \ - source /etc/rubybashrc && \ - rvm autolibs disable && \ - rvmsudo rvm cleanup all " - -# Import patch files for ruby and gems -COPY build/patches /home/rvm/patches/ - -# install rubies and fix permissions on -ENV RVM_RUBIES 2.5.9 3.1.0 -RUN bash -c " \ - export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \ - for v in ${RVM_RUBIES} ; do \ - rvm install \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \ - done && \ - rvm cleanup all && \ - find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " - -# Install rake-compiler and typical gems in all Rubies -# do not generate documentation for gems -# TODO: stop pinning rubygems to 3.3.20 once https://github.com/rake-compiler/rake-compiler/pull/209 is merged -RUN echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \ - bash -c " \ - rvm all do gem update --system=3.3.20 --no-document && \ - rvm all do gem install --no-document bundler 'bundler:~>1.16' 'rake-compiler:1.1.6' hoe mini_portile rubygems-tasks mini_portile2 && \ - find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " - -# Install rake-compiler's cross rubies in global dir instead of /root -RUN sudo mkdir -p /usr/local/rake-compiler && \ - sudo chown rvm.rvm /usr/local/rake-compiler && \ - ln -s /usr/local/rake-compiler ~/.rake-compiler - -# Add cross compilers for Windows and Linux -USER root - -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 \ - /debs/ -RUN dpkg -i /debs/*.deb - - -RUN bash -c " \ - rvm alias create default 3.1.0 && \ - rvm use default " - - - -# Patch rake-compiler to build and install static libraries for Linux rubies -USER rvm -COPY build/patches2 /home/rvm/patches/ -RUN bash -c " \ - for v in ${RVM_RUBIES} ; do \ - cd /usr/local/rvm/gems/ruby-\$v/gems/rake-compiler-1.1.6 && \ - echo applying patches to ruby-\$v /home/rvm/patches/rake-compiler-1.1.6/*.patch && \ - ( git apply /home/rvm/patches/rake-compiler-1.1.6/*.patch || true ) \ - done " - -# Patch rubies for cross build -#USER root -#RUN bash -c " \ -# for v in 2.7.0 3.0.0 3.1.0 ; do \ -# curl -SL http://cache.ruby-lang.org/pub/ruby/\${v:0:3}/ruby-\$v.tar.xz | tar -xJC /root/ && \ -# cd /root/ruby-\$v && \ -# git apply /home/rvm/patches/ruby-\$v/*.patch && \ -# cd .. && \ -# mkdir -p /usr/local/rake-compiler/sources/ && \ -# tar cjf /usr/local/rake-compiler/sources/ruby-\$v.tar.bz2 ruby-\$v && \ -# chown rvm /usr/local/rake-compiler -R && \ -# rm -rf /root/ruby-\$v ; \ -# done " -#USER rvm - -ENV XRUBIES 3.2.0-rc1 -# Build xruby versions in parallel -# Then cleanup all build artifacts -RUN bash -c " \ - rvm use 3.1.0 && \ - export CPPFLAGS='-D__USE_MINGW_ANSI_STDIO=1' && \ - export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong -s' && \ - export LDFLAGS='-pipe -s' && \ - export LIBS='-l:libssp.a' && \ - \ - export MAKE='make V=1 -j`nproc`' && \ - rake-compiler cross-ruby VERSION=$XRUBIES HOST=x86_64-w64-mingw32 && \ - rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \ - find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " -ENV XRUBIES 3.1.0 -# Build xruby versions in parallel -# Then cleanup all build artifacts -RUN bash -c " \ - rvm use 3.1.0 && \ - export CPPFLAGS='-D__USE_MINGW_ANSI_STDIO=1' && \ - export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong -s' && \ - export LDFLAGS='-pipe -s' && \ - export LIBS='-l:libssp.a' && \ - \ - export MAKE='make V=1 -j`nproc`' && \ - rake-compiler cross-ruby VERSION=$XRUBIES HOST=x86_64-w64-mingw32 && \ - rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \ - find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " - - -# RubyInstaller doesn't install libgcc -> link it static. -RUN find /usr/local/rake-compiler/ruby/*mingw*/ -name rbconfig.rb | while read f ; do sed -i 's/."LDFLAGS". = "/&-static-libgcc /' $f ; done -# Raise Windows-API to Vista (affects ruby < 2.6 only) -RUN find /usr/local/rake-compiler/ruby -name rbconfig.rb | while read f ; do sed -i 's/0x0501/0x0600/' $f ; done -# Don't link to static libruby -RUN find /usr/local/rake-compiler/ruby -name lib*-ruby*.dll.a | while read f ; do n=`echo $f | sed s/.dll//` ; mv $f $n ; done - -USER root - -# Fix paths in rake-compiler/config.yml -RUN sed -i -- "s:/root/.rake-compiler:/usr/local/rake-compiler:g" /usr/local/rake-compiler/config.yml - - -# Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker. -COPY build/strip_wrapper /root/ -RUN mv /usr/bin/x86_64-w64-mingw32-strip /usr/bin/x86_64-w64-mingw32-strip.bin && \ - ln /root/strip_wrapper /usr/bin/x86_64-w64-mingw32-strip - -# Use posix pthread for mingw so that C++ standard library for thread could be -# available such as std::thread, std::mutex, so on. -# https://sourceware.org/pthreads-win32/ -RUN printf "1\n" | update-alternatives --config x86_64-w64-mingw32-gcc && \ - printf "1\n" | update-alternatives --config x86_64-w64-mingw32-g++ - - - -# Install SIGINT forwarder -COPY build/sigfw.c /root/ -RUN gcc $HOME/sigfw.c -o /usr/bin/sigfw - -# Install user mapper -COPY build/runas /usr/bin/ -COPY build/rcd-env.sh /etc/profile.d/ -RUN echo "source /etc/profile.d/rcd-env.sh" >> /etc/rubybashrc - -# Install sudoers configuration -COPY build/sudoers /etc/sudoers.d/rake-compiler-dock - -ENV RUBY_CC_VERSION 3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0:2.4.0 - -CMD bash diff --git a/build/setup_dpkg_multiarch_for_target.sh b/build/setup_dpkg_multiarch_for_target.sh index 657899cf..db623445 100755 --- a/build/setup_dpkg_multiarch_for_target.sh +++ b/build/setup_dpkg_multiarch_for_target.sh @@ -4,39 +4,18 @@ set -exuo pipefail IFS=$'\n\t' main() { - local to_uninstall=() - - if ! command -v dpkg-architecture; then - echo "dpkg-architecture not found, installing" >&2 - apt-get -qq -y update - apt-get -qq -y install --no-install-recommends debhelper lsb-release - rm -rf /var/lib/apt/lists/* - to_uninstall+=("debhelper" "lsb-release") - fi - - deb_host_arch="$(dpkg-architecture --query DEB_HOST_ARCH)" + deb_host_arch="$(dpkg --print-architecture)" deb_target_arch="$1" if [ "$deb_target_arch" != "$deb_host_arch" ]; then echo "Setting up multiarch support for $deb_target_arch" >&2 - # Add arch support for target so we can install libs dpkg --add-architecture "$deb_target_arch" - # Qualify our current source lists to make sure debian doesn't infer stuff - sed -i "s/^deb http/deb [arch=$deb_host_arch] http/" /etc/apt/sources.list - # Add sources for ported target libs - sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main universe restricted multiverse\" >> /etc/apt/sources.list" - sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main universe restricted multiverse\" >> /etc/apt/sources.list" - sh -c "echo \"deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-security main universe restricted multiverse\" >> /etc/apt/sources.list" - apt-get update + apt-get -qq -y update else echo "No need to set up multiarch support for $deb_target_arch" fi - if [ "${#to_uninstall[@]}" -gt 0 ]; then - apt-get remove -y "${to_uninstall[@]}" - fi - rm "$0" } From b489f4f2005915fe3b3ffbb4345c47274f5d5018 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 16:41:52 -0500 Subject: [PATCH 24/30] [linux/arm64] Cleanup multiarch stuff --- Dockerfile.mri.erb | 6 +++--- ...ltiarch_for_target.sh => apt_install_multiarch.sh} | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) rename build/{setup_dpkg_multiarch_for_target.sh => apt_install_multiarch.sh} (69%) diff --git a/Dockerfile.mri.erb b/Dockerfile.mri.erb index db82e689..7df1d281 100644 --- a/Dockerfile.mri.erb +++ b/Dockerfile.mri.erb @@ -23,12 +23,12 @@ RUN rm -f /usr/local/bin/sudo && \ echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers <% else %> ENV DEBIAN_FRONTEND noninteractive -COPY ./build/setup_dpkg_multiarch_for_target.sh / -RUN /setup_dpkg_multiarch_for_target.sh <%= foreign_dpkg_arch %>; + +COPY ./build/apt_install_multiarch.sh / +RUN /apt_install_multiarch.sh <%= foreign_dpkg_arch %> zlib1g-dev libreadline-dev libsqlite0-dev libssl-dev libyaml-dev libffi-dev RUN apt-get -y -qq update && \ apt-get -y -qq install sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr && \ - apt-get -y -qq install zlib1g-dev:<%= foreign_dpkg_arch %> libreadline-dev:<%= foreign_dpkg_arch %> libsqlite0-dev:<%= foreign_dpkg_arch %> libssl-dev:<%= foreign_dpkg_arch %> libyaml-dev:<%= foreign_dpkg_arch %> libffi-dev:<%= foreign_dpkg_arch %> && \ rm -rf /var/lib/apt/lists/*; <% end %> diff --git a/build/setup_dpkg_multiarch_for_target.sh b/build/apt_install_multiarch.sh similarity index 69% rename from build/setup_dpkg_multiarch_for_target.sh rename to build/apt_install_multiarch.sh index db623445..78692ba7 100755 --- a/build/setup_dpkg_multiarch_for_target.sh +++ b/build/apt_install_multiarch.sh @@ -7,15 +7,22 @@ main() { deb_host_arch="$(dpkg --print-architecture)" deb_target_arch="$1" + shift + + packages=("$@") + if [ "$deb_target_arch" != "$deb_host_arch" ]; then echo "Setting up multiarch support for $deb_target_arch" >&2 - dpkg --add-architecture "$deb_target_arch" - apt-get -qq -y update + packages=("${packages[@]/%/:$deb_target_arch}") else echo "No need to set up multiarch support for $deb_target_arch" fi + apt-get -qq -y update + apt-get -qq -y install "${packages[@]}" + rm -rf /var/lib/apt/lists/* + rm "$0" } From 4cced6672fa3cd0b720363745b42820e5587f31e Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 16:51:12 -0500 Subject: [PATCH 25/30] [linux/arm64] Another guard --- build/apt_install_multiarch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/apt_install_multiarch.sh b/build/apt_install_multiarch.sh index 78692ba7..863920c4 100755 --- a/build/apt_install_multiarch.sh +++ b/build/apt_install_multiarch.sh @@ -11,7 +11,7 @@ main() { packages=("$@") - if [ "$deb_target_arch" != "$deb_host_arch" ]; then + if [ "$deb_target_arch" != "$deb_host_arch" ] && [ "$deb_target_arch" != "amd64" ]; then echo "Setting up multiarch support for $deb_target_arch" >&2 dpkg --add-architecture "$deb_target_arch" packages=("${packages[@]/%/:$deb_target_arch}") From ccfaa41bb43b5936eb7cba62ac866a82ec2e13e0 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 16:53:45 -0500 Subject: [PATCH 26/30] [linux/arm64] Install both types of pkgs --- build/apt_install_multiarch.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/apt_install_multiarch.sh b/build/apt_install_multiarch.sh index 863920c4..72907c71 100755 --- a/build/apt_install_multiarch.sh +++ b/build/apt_install_multiarch.sh @@ -9,18 +9,19 @@ main() { shift + cross_packages=() packages=("$@") if [ "$deb_target_arch" != "$deb_host_arch" ] && [ "$deb_target_arch" != "amd64" ]; then echo "Setting up multiarch support for $deb_target_arch" >&2 dpkg --add-architecture "$deb_target_arch" - packages=("${packages[@]/%/:$deb_target_arch}") + cross_packages=("${packages[@]/%/:$deb_target_arch}") else echo "No need to set up multiarch support for $deb_target_arch" fi apt-get -qq -y update - apt-get -qq -y install "${packages[@]}" + apt-get -qq -y install "${packages[@]}" "${cross_packages[@]}" rm -rf /var/lib/apt/lists/* rm "$0" From 41cae4e59367a90ed43147006463550d46df012f Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 16:55:55 -0500 Subject: [PATCH 27/30] [linux/arm64] Another guard --- build/apt_install_multiarch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/apt_install_multiarch.sh b/build/apt_install_multiarch.sh index 72907c71..99a1f891 100755 --- a/build/apt_install_multiarch.sh +++ b/build/apt_install_multiarch.sh @@ -12,7 +12,7 @@ main() { cross_packages=() packages=("$@") - if [ "$deb_target_arch" != "$deb_host_arch" ] && [ "$deb_target_arch" != "amd64" ]; then + if [ "$deb_target_arch" != "$deb_host_arch" ] && [ "$deb_target_arch" = "arm64" ]; then echo "Setting up multiarch support for $deb_target_arch" >&2 dpkg --add-architecture "$deb_target_arch" cross_packages=("${packages[@]/%/:$deb_target_arch}") From 760881374946602ce1288fff679c0b031a676817 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 17:06:32 -0500 Subject: [PATCH 28/30] [linux/arm64] Manipulate sources --- build/apt_install_multiarch.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/apt_install_multiarch.sh b/build/apt_install_multiarch.sh index 99a1f891..9eb0679b 100755 --- a/build/apt_install_multiarch.sh +++ b/build/apt_install_multiarch.sh @@ -5,6 +5,7 @@ IFS=$'\n\t' main() { deb_host_arch="$(dpkg --print-architecture)" + lsb_release="$(grep VERSION_CODENAME < /etc/os-release | cut -d= -f2 | tr -d '"')" deb_target_arch="$1" shift @@ -16,6 +17,14 @@ main() { echo "Setting up multiarch support for $deb_target_arch" >&2 dpkg --add-architecture "$deb_target_arch" cross_packages=("${packages[@]/%/:$deb_target_arch}") + + # Qualify our current source lists to make sure debian doesn't infer stuff + sed -i "s/^deb http/deb [arch=$deb_host_arch] http/" /etc/apt/sources.list + + # Add sources for ported target libs + echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main universe restricted multiverse" + echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main universe restricted multiverse" + echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-security main universe restricted multiverse" else echo "No need to set up multiarch support for $deb_target_arch" fi From dfbedba4a1c9f13c3d6277a6024e1306ad63f711 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 18:06:37 -0500 Subject: [PATCH 29/30] [linux/arm64] Derive lsb_relese --- build/apt_install_multiarch.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/apt_install_multiarch.sh b/build/apt_install_multiarch.sh index 9eb0679b..321dc5a5 100755 --- a/build/apt_install_multiarch.sh +++ b/build/apt_install_multiarch.sh @@ -22,9 +22,9 @@ main() { sed -i "s/^deb http/deb [arch=$deb_host_arch] http/" /etc/apt/sources.list # Add sources for ported target libs - echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main universe restricted multiverse" - echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main universe restricted multiverse" - echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-security main universe restricted multiverse" + echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $lsb_release main universe restricted multiverse" + echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $lsb_release-updates main universe restricted multiverse" + echo "deb [arch=$deb_target_arch] http://ports.ubuntu.com/ubuntu-ports $lsb_release-security main universe restricted multiverse" else echo "No need to set up multiarch support for $deb_target_arch" fi From 44a653a0c1b8de5cf2f5494772cd264f83553356 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Sat, 17 Dec 2022 18:10:40 -0500 Subject: [PATCH 30/30] [linux/arm64] Only install multiarch when host is arm64 --- build/apt_install_multiarch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/apt_install_multiarch.sh b/build/apt_install_multiarch.sh index 321dc5a5..561f816d 100755 --- a/build/apt_install_multiarch.sh +++ b/build/apt_install_multiarch.sh @@ -13,7 +13,7 @@ main() { cross_packages=() packages=("$@") - if [ "$deb_target_arch" != "$deb_host_arch" ] && [ "$deb_target_arch" = "arm64" ]; then + if [ "$deb_target_arch" != "$deb_host_arch" ] && [ "$deb_host_arch" = "arm64" ]; then echo "Setting up multiarch support for $deb_target_arch" >&2 dpkg --add-architecture "$deb_target_arch" cross_packages=("${packages[@]/%/:$deb_target_arch}")