From 7e62481198cf92916e387b6d149353dd2a458104 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 13 May 2022 20:19:10 +0200 Subject: [PATCH 1/5] c2rust: Install via riotbuild This has become possible now that it doesn't need fancy build dependencies any more. --- c2rust-built/Dockerfile | 95 ----------------------------------- c2rust-built/README.md | 28 ----------- c2rust-built/debian/changelog | 5 -- c2rust-built/debian/control | 18 ------- c2rust-built/debian/rules | 10 ---- riotbuild/Dockerfile | 11 +++- 6 files changed, 9 insertions(+), 158 deletions(-) delete mode 100644 c2rust-built/Dockerfile delete mode 100644 c2rust-built/README.md delete mode 100644 c2rust-built/debian/changelog delete mode 100644 c2rust-built/debian/control delete mode 100755 c2rust-built/debian/rules diff --git a/c2rust-built/Dockerfile b/c2rust-built/Dockerfile deleted file mode 100644 index cce24880..00000000 --- a/c2rust-built/Dockerfile +++ /dev/null @@ -1,95 +0,0 @@ -ARG DOCKER_REGISTRY="riot" -FROM ${DOCKER_REGISTRY}/riotdocker-base:latest - -COPY debian/control /dpkg-build/debian/ -# When playing with these, it is often practical to remove the comments on the -# `# true` / ... / `# RUN \` blocks (making the resulting images larger because -# of the intermediate files in the chain, but quick to rebuild on small -# changes) and moving the COPY lines down before the `dpkg-buildpackage` to not -# download and install all the dependencies again. The control file needs to -# stay up there as it influences what will be installed. -COPY debian/rules /dpkg-build/debian/ -COPY debian/changelog /dpkg-build/debian/ - -# noninteractive for the tzinfo -RUN \ - echo 'Update the package index files to latest available versions' >&2 && \ - apt-get update && \ - echo 'Install Build / install dependencies' >&2 && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - curl \ - debhelper \ - devscripts \ - dpkg-dev \ - equivs \ - && \ - mk-build-deps -i /dpkg-build/debian/control -t 'apt-get -y --no-install-recommends' && \ - echo 'Clean up installation files' >&2 && \ - apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ -# true -# -# # Note that --profile minimal doesn't cut it -# RUN \ - echo 'Install c2rust rust' >&2 && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ -# true -# -# # Build using the provided Debian package sources -# # -# RUN \ - mkdir -p /dpkg-build/debian && \ - cd /dpkg-build && \ -# true -# -# # Build using Debian's mechanism; the actual build line is in ./debian/rules -# RUN \ - cd /dpkg-build && \ - PATH=~/.cargo/bin:$PATH dpkg-buildpackage -b && \ - cd / && \ -# true -# -# # Cleaning up as the relevant files were copied out, and the rest would just -# # make for a large image (which should only contain a minimal delta to the base -# # image in the end: the installed dependencies (libllvm), the installed -# # binaries and the debs that contain the stripped binaries and separate debug -# # symbols once more) -# RUN \ - rm -rf /dpkg-build && \ - rm -rf ~/.cargo && \ - rm -rf ~/.rustup && \ -# true -# -# # Besides copying the c2rust files to /usr/bin (which could also have been done -# # with --root /usr in the cargo line), this also ensures that the dependencies -# # stick around through the next step. -# RUN \ - apt-get -y install /c2rust_*.deb && \ -# true -# -# # Provide the package in an easy to match place independent of version and -# # architecture -# RUN \ - cp -l /c2rust_*.deb /c2rust.deb && \ -# true -# -# # TBD: Deduplicate list with above; feisty apt-get has no --mark-auto, -# # otherwise we could just --mark-auto above and autoremove --purge here. -# RUN \ - echo 'Removing packages only needed for building from container' >&2 && \ - apt-get purge -y --auto-remove \ - build-essential \ - ca-certificates \ - curl \ - debhelper \ - devscripts \ - dpkg-dev \ - equivs \ - c2rust-build-deps \ - && \ - echo 'Cleanup done' - -# Check they're still executable -RUN c2rust --version -RUN c2rust-transpile --version diff --git a/c2rust-built/README.md b/c2rust-built/README.md deleted file mode 100644 index 40eb9f9f..00000000 --- a/c2rust-built/README.md +++ /dev/null @@ -1,28 +0,0 @@ -This image contains built and usable versions of [c2rust]. -It is provided because upstream [does not release binaries] for c2rust and its companion tools. - -As this changes rarely, -and because on the github-workers infrastructure this is [difficult to get right], -this is not built and used through CI yet, -but manually built an published as: - - docker build . -t chrysn/c2rust-built - -The resulting image fulfils three roles: - -* c2rust can be executed in there immediately, or used as a base for other images. -* The binaries in `/usr/bin/c2rust` can be extracted and used in other images. -* The `./c2rust.deb` package can be copied and installed in other images. - Unlike copying the binaries over, this also ensures that the right LLVM dependencies are installed there. - -The parts that can be meaningfully performed by a Debian package are, -and the relevant files are located in the `debian/` directory. -As a side effect, -packages can be built using the same infrastructure even without a Docker container: -as long as a recent Rust version is present -and all the typical Debian tools are around, -`dpkg-buildpackage -b` will produce a usable package for the Debian (or derivative) installed on the system. - -[c2rust]: https://github.com/immunant/c2rust -[does not release binaries]: https://github.com/immunant/c2rust/issues/326 -[difficult to get right]: https://github.com/RIOT-OS/riotdocker/pull/141 diff --git a/c2rust-built/debian/changelog b/c2rust-built/debian/changelog deleted file mode 100644 index 0561e495..00000000 --- a/c2rust-built/debian/changelog +++ /dev/null @@ -1,5 +0,0 @@ -c2rust (0.16.0-0) UNRELEASED; urgency=medium - - * Initial package as part of the riotdocker builds. - - -- Christian M. Amsüss Fri, 13 May 2022 09:06:27 +0200 diff --git a/c2rust-built/debian/control b/c2rust-built/debian/control deleted file mode 100644 index 322c4215..00000000 --- a/c2rust-built/debian/control +++ /dev/null @@ -1,18 +0,0 @@ -Source: c2rust -Section: devel -Priority: extra -Maintainer: Christian Amsüss -Build-Depends: cmake, - debhelper-compat (= 12), - libclang-dev, - libssl-dev, - llvm-dev, - pkg-config - -Package: c2rust -Architecture: any -Depends: ${misc:Depends}, ${shlibs:Depends} -Description: c2rust transpiler - A tool to translate C modules into semantically equivalent Rust code. - . - This package is built as part of RIOT's docker image creation. diff --git a/c2rust-built/debian/rules b/c2rust-built/debian/rules deleted file mode 100755 index 800ab62d..00000000 --- a/c2rust-built/debian/rules +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- - -%: - dh $@ - -override_dh_auto_install: - cargo install --no-track --locked c2rust --git https://github.com/chrysn-pull-requests/c2rust --branch for-riot-20220513 --root debian/c2rust/usr - # For unknown reasons --no-track doesn't keep cargo from installing .crates.toml and .crates2.json - rm -f debian/c2rust/usr/.??* diff --git a/riotbuild/Dockerfile b/riotbuild/Dockerfile index 746b735d..6c48013e 100644 --- a/riotbuild/Dockerfile +++ b/riotbuild/Dockerfile @@ -34,8 +34,6 @@ RUN mkdir /pkgs COPY files/libsocketcan-dev_0.0.11-1_i386.deb /pkgs/libsocketcan-dev_0.0.11-1_i386.deb COPY files/libsocketcan2_0.0.11-1_i386.deb /pkgs/libsocketcan2_0.0.11-1_i386.deb -COPY --from=chrysn/c2rust-built:for-riot /c2rust.deb /pkgs - # The following package groups will be installed: # - update the package index files to latest available version # - native platform development and build system functionality (about 400 MB installed) @@ -108,6 +106,12 @@ RUN \ clang \ clang-tools \ && \ + && echo 'Installing C2Rust (build) dependencies' >&2 && \ + apt-get -y --no-install-recommends install \ + libclang-dev \ + libssl-dev \ + llvm-dev \ + && \ SYMS=$(find /usr/bin -type l) && \ for file in ${SYMS}; do \ SYMTARGET=$(readlink -f ${file}) && \ @@ -309,6 +313,9 @@ RUN \ true; \ done" +RUN \ + cargo install --no-track --locked c2rust --git https://github.com/chrysn-pull-requests/c2rust --branch for-riot-20220513 + # get Dockerfile version from build args ARG RIOTBUILD_VERSION=unknown ENV RIOTBUILD_VERSION $RIOTBUILD_VERSION From 792353cd23304c8967290327bde6ab18d9643f79 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 13 May 2022 20:21:17 +0200 Subject: [PATCH 2/5] c2rust: Update version This unblocks a stage of [#18056]. [#18056]: https://github.com/RIOT-OS/RIOT/pull/18056 --- riotbuild/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/riotbuild/Dockerfile b/riotbuild/Dockerfile index 6c48013e..622de214 100644 --- a/riotbuild/Dockerfile +++ b/riotbuild/Dockerfile @@ -105,7 +105,6 @@ RUN \ llvm \ clang \ clang-tools \ - && \ && echo 'Installing C2Rust (build) dependencies' >&2 && \ apt-get -y --no-install-recommends install \ libclang-dev \ @@ -314,7 +313,7 @@ RUN \ done" RUN \ - cargo install --no-track --locked c2rust --git https://github.com/chrysn-pull-requests/c2rust --branch for-riot-20220513 + cargo install --no-track --locked c2rust --git https://github.com/chrysn-pull-requests/c2rust --branch for-riot-20220513b # get Dockerfile version from build args ARG RIOTBUILD_VERSION=unknown From d084ef0b851e5c6e7b3570bfc9c8a643d48d27ea Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 13 May 2022 21:29:28 +0200 Subject: [PATCH 3/5] export CARGO_HOME environment variable This is required to make any `cargo install` work given the locations. --- riotbuild/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/riotbuild/Dockerfile b/riotbuild/Dockerfile index 622de214..1e480b9c 100644 --- a/riotbuild/Dockerfile +++ b/riotbuild/Dockerfile @@ -293,9 +293,10 @@ ENV PATH ${PATH}:/opt/rustup/.cargo/bin # needed on AVR (which thus doesn't need the avr-unknown-gnu-atmega328 target; # being able to build core might be useful for other targets as well). ENV RUSTUP_HOME /opt/rustup/.rustup +ENV CARGO_HOME /opt/rustup/.cargo RUN \ RUSTUP_HOME=/opt/rustup/.rustup \ - CARGO_HOME=/opt/rustup/.cargo sh -c "\ + sh -c "\ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain nightly-2022-03-08 && \ rustup toolchain add stable && \ for T in nightly-2022-03-08 stable; do \ From 8b06c23d3fe7f824848c9b45e804f81367a701c5 Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 14 May 2022 08:50:40 +0200 Subject: [PATCH 4/5] Revert "export CARGO_HOME environment variable" This reverts commit d084ef0b851e5c6e7b3570bfc9c8a643d48d27ea. --- riotbuild/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/riotbuild/Dockerfile b/riotbuild/Dockerfile index 1e480b9c..622de214 100644 --- a/riotbuild/Dockerfile +++ b/riotbuild/Dockerfile @@ -293,10 +293,9 @@ ENV PATH ${PATH}:/opt/rustup/.cargo/bin # needed on AVR (which thus doesn't need the avr-unknown-gnu-atmega328 target; # being able to build core might be useful for other targets as well). ENV RUSTUP_HOME /opt/rustup/.rustup -ENV CARGO_HOME /opt/rustup/.cargo RUN \ RUSTUP_HOME=/opt/rustup/.rustup \ - sh -c "\ + CARGO_HOME=/opt/rustup/.cargo sh -c "\ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain nightly-2022-03-08 && \ rustup toolchain add stable && \ for T in nightly-2022-03-08 stable; do \ From 529f6d4ab65f6cca15908e99ff2f6e08ab97d120 Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 14 May 2022 08:52:57 +0200 Subject: [PATCH 5/5] fixup! c2rust: Install via riotbuild --- riotbuild/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/riotbuild/Dockerfile b/riotbuild/Dockerfile index 622de214..e5c68979 100644 --- a/riotbuild/Dockerfile +++ b/riotbuild/Dockerfile @@ -313,7 +313,10 @@ RUN \ done" RUN \ - cargo install --no-track --locked c2rust --git https://github.com/chrysn-pull-requests/c2rust --branch for-riot-20220513b + echo 'Installing C2Rust' >&2 && \ + CARGO_HOME=/opt/rustup/.cargo cargo install --no-track --locked c2rust --git https://github.com/chrysn-pull-requests/c2rust --branch for-riot-20220513b && \ + echo 'Cleaning up root-owned crates.io cache' >&2 && \ + rm -rf /opt/rustup/.cargo/{git,registry,.package-cache} # get Dockerfile version from build args ARG RIOTBUILD_VERSION=unknown