Refactor binary-compatible-builds for releases (#4171)

* Refactor binary-compatible-builds for releases

I was poking around this yesterday and noticed a few things that could
be improved for our release builds:

* The centos container for the x86_64 builds contained a bunch of extra
  tooling we no longer need such as python3 and a C++ compiler. Along
  with custom toolchain things this could all get removed since the C we
  include now is quite simple.

* The aarch64 and s390x cross-compiled builds had relatively high glibc
  version requirements compared to the x86_64 build. This was because we
  don't use a container to build the cross-compiled binaries. I added
  containers here along the lines of the x86_64 build to use an older
  glibc to build the release binary to lower our version requirement.
  This lower the aarch64 version requirement from glibc 2.28 to 2.17.
  Additionally the s390x requirement dropped from 2.28 to 2.16.

* To make the containers a bit easier to read/write I added
  `Dockerfile`s for them in a new `ci/docker` directory instead of
  hardcoding install commands in JS.

This isn't intended to be a really big change or anything for anyone,
but it's intended to keep our Linux-based builds consistent at least as
best we can.

* Remove temporary change
This commit is contained in:
Alex Crichton
2022-05-20 12:13:50 -05:00
committed by GitHub
parent 985ed07c3f
commit 08b7c87793
6 changed files with 37 additions and 45 deletions

View File

@@ -4,3 +4,7 @@ description: 'Set up a CentOS 6 container to build releases in'
runs:
using: node12
main: 'main.js'
inputs:
name:
required: true
description: "Name of the build"

View File

@@ -12,14 +12,12 @@ function set_env(name, val) {
// possible. For now 10.9 is the limit.
if (process.platform == 'darwin') {
set_env("MACOSX_DEPLOYMENT_TARGET", "10.9");
set_env("python", "python3");
return;
}
// On Windows we build against the static CRT to reduce dll dependencies
if (process.platform == 'win32') {
set_env("RUSTFLAGS", "-Ctarget-feature=+crt-static");
set_env("python", "python");
return;
}
@@ -28,7 +26,7 @@ if (process.platform == 'win32') {
// commands in there with the `$CENTOS` env var.
if (process.env.CENTOS !== undefined) {
const args = ['exec', '-w', process.cwd(), '-i', 'centos'];
const args = ['exec', '-w', process.cwd(), '-i', 'build-container'];
for (const arg of process.argv.slice(2)) {
args.push(arg);
}
@@ -36,40 +34,23 @@ if (process.env.CENTOS !== undefined) {
return;
}
// Add our rust mount onto PATH, but also add some stuff to PATH from
// the packages that we install.
let path = process.env.PATH;
path = `${path}:/rust/bin`;
path = `/opt/rh/devtoolset-8/root/usr/bin:${path}`;
const name = process.env.INPUT_NAME;
child_process.execFileSync('docker', [
'build',
'--tag', 'build-image',
`${process.cwd()}/ci/docker/${name}`
], stdio);
// Spawn a container daemonized in the background which we'll connect to via
// `docker exec`. This'll have access to the current directory.
child_process.execFileSync('docker', [
'run',
'-di',
'--name', 'centos',
'--detach',
'--interactive',
'--name', 'build-container',
'-v', `${process.cwd()}:${process.cwd()}`,
'-v', `${child_process.execSync('rustc --print sysroot').toString().trim()}:/rust:ro`,
'--env', `PATH=${path}`,
// FIXME(rust-lang/rust#80703) this shouldn't be necessary
'--env', `LD_LIBRARY_PATH=/rust/lib`,
'centos:7',
'build-image',
], stdio);
// Use ourselves to run future commands
set_env("CENTOS", __filename);
// See https://edwards.sdsu.edu/research/c11-on-centos-6/ for where these
const exec = s => {
child_process.execSync(`docker exec centos ${s}`, stdio);
};
exec('yum install -y centos-release-scl cmake xz epel-release');
exec('yum install -y python3 patchelf unzip');
exec('yum install -y devtoolset-8-gcc devtoolset-8-binutils devtoolset-8-gcc-c++');
exec('yum install -y git');
// Delete `libstdc++.so` to force gcc to link against `libstdc++.a` instead.
// This is a hack and not the right way to do this, but it ends up doing the
// right thing for now.
exec('rm -f /opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.so');
set_env("python", "python3");

View File

@@ -376,29 +376,17 @@ jobs:
- build: aarch64-linux
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
gcc_package: gcc-aarch64-linux-gnu
gcc: aarch64-linux-gnu-gcc
- build: s390x-linux
os: ubuntu-latest
target: s390x-unknown-linux-gnu
gcc_package: gcc-s390x-linux-gnu
gcc: s390x-linux-gnu-gcc
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: ./.github/actions/install-rust
- uses: ./.github/actions/binary-compatible-builds
if: matrix.target == ''
- name: Install cross-compilation tools
run: |
set -ex
sudo apt-get update
sudo apt-get install -y ${{ matrix.gcc_package }}
upcase=$(echo ${{ matrix.target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
echo CARGO_TARGET_${upcase}_LINKER=${{ matrix.gcc }} >> $GITHUB_ENV
if: matrix.target != '' && matrix.os == 'ubuntu-latest'
with:
name: ${{ matrix.build }}
- run: |
echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
rustup target add ${{ matrix.target }}

View File

@@ -0,0 +1,7 @@
FROM ubuntu:16.04
RUN apt-get update -y && apt-get install -y gcc gcc-aarch64-linux-gnu ca-certificates
ENV PATH=$PATH:/rust/bin
ENV CARGO_BUILD_TARGET=aarch64-unknown-linux-gnu
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc

View File

@@ -0,0 +1,7 @@
FROM ubuntu:16.04
RUN apt-get update -y && apt-get install -y gcc gcc-s390x-linux-gnu ca-certificates
ENV PATH=$PATH:/rust/bin
ENV CARGO_BUILD_TARGET=s390x-unknown-linux-gnu
ENV CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER=s390x-linux-gnu-gcc

View File

@@ -0,0 +1,5 @@
FROM centos:7
RUN yum install -y git gcc
ENV PATH=$PATH:/rust/bin