From 4ad2b63cd41e19ae55e8e8754bcfdc4b984ec611 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles@codethink.co.uk>
Date: Fri, 24 Apr 2020 14:58:12 +0100
Subject: [PATCH 1/2] Add riscvgc-unknown-linux-gnu support

---
 README.md                                     |  1 +
 azure-pipelines.yml                           |  1 +
 docker/Dockerfile.riscv64gc-unknown-linux-gnu | 26 +++++++++++++++++++
 3 files changed, 28 insertions(+)
 create mode 100644 docker/Dockerfile.riscv64gc-unknown-linux-gnu

diff --git a/README.md b/README.md
index 708166beb..6a13e8faf 100644
--- a/README.md
+++ b/README.md
@@ -267,6 +267,7 @@ terminate.
 | `powerpc-unknown-linux-gnu`          | 2.19   | 4.8.2   | ✓   | 3.0.1 |   ✓    |
 | `powerpc64-unknown-linux-gnu`        | 2.19   | 4.8.2   | ✓   | 3.0.1 |   ✓    |
 | `powerpc64le-unknown-linux-gnu`      | 2.19   | 4.8.2   | ✓   | 3.0.1 |   ✓    |
+| `riscv64gc-unknown-linux-gnu`        | 2.27   | 7.5.0   | ✓   | 4.2.0 |   ✓    |
 | `s390x-unknown-linux-gnu`            | 2.23   | 5.3.1   | ✓   | 4.1.0 |        |
 | `sparc64-unknown-linux-gnu` [3]      | 2.23   | 5.3.1   | ✓   | 4.1.0 |   ✓    |
 | `sparcv9-sun-solaris` [4]            | 2.11   | 5.3.0   | ✓   | N/A   |        |
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 8aebc02ef..0cffdfe09 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -32,6 +32,7 @@ jobs:
         powerpc-unknown-linux-gnu:       { TARGET: powerpc-unknown-linux-gnu,       CPP: 1, DYLIB: 1, STD: 1, RUN: 1, RUNNERS: qemu-user qemu-system }
         powerpc64-unknown-linux-gnu:     { TARGET: powerpc64-unknown-linux-gnu,     CPP: 1, DYLIB: 1, STD: 1, RUN: 1, RUNNERS: qemu-user qemu-system }
         powerpc64le-unknown-linux-gnu:   { TARGET: powerpc64le-unknown-linux-gnu,   CPP: 1, DYLIB: 1, STD: 1, RUN: 1, RUNNERS: qemu-user qemu-system }
+        riscv64gc-unknown-linux-gnu:     { TARGET: riscv64gc-unknown-linux-gnu,     CPP: 1,           STD: 1, RUN: 1 }
         s390x-unknown-linux-gnu:         { TARGET: s390x-unknown-linux-gnu,         CPP: 1, DYLIB: 1, STD: 1, RUN: 1, RUNNERS: qemu-system }
         sparc64-unknown-linux-gnu:       { TARGET: sparc64-unknown-linux-gnu,       CPP: 1, DYLIB: 1, STD: 1, RUN: 1, RUNNERS: qemu-system }
         x86_64-unknown-linux-gnu:        { TARGET: x86_64-unknown-linux-gnu,        CPP: 1, DYLIB: 1, STD: 1, RUN: 1, RUNNERS: native qemu-user qemu-system, DEPLOY: 1, CRATES_IO_PUBLISH: 1 }
diff --git a/docker/Dockerfile.riscv64gc-unknown-linux-gnu b/docker/Dockerfile.riscv64gc-unknown-linux-gnu
new file mode 100644
index 000000000..3d62c55ca
--- /dev/null
+++ b/docker/Dockerfile.riscv64gc-unknown-linux-gnu
@@ -0,0 +1,26 @@
+FROM ubuntu:18.04
+
+COPY common.sh /
+RUN /common.sh
+
+# COPY cmake.sh /
+# RUN /cmake.sh
+
+COPY xargo.sh /
+RUN /xargo.sh
+
+RUN apt-get install -y --no-install-recommends \
+    g++-riscv64-linux-gnu \
+    libc6-dev-riscv64-cross
+
+COPY qemu.sh /
+RUN /qemu.sh riscv64
+
+COPY linux-runner /
+
+ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc \
+    CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="/linux-runner riscv64" \
+    CC_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-gcc \
+    CXX_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-g++ \
+    QEMU_LD_PREFIX=/usr/riscv64-linux-gnu \
+    RUST_TEST_THREADS=1

From a7d64825c816d85ffd1a0d8b2afb391c03757d32 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles@codethink.co.uk>
Date: Thu, 30 Apr 2020 18:33:38 +0100
Subject: [PATCH 2/2] ci: powerpc: Allow unauthenticated packages

Reading package lists...
W: GPG error: http://archive.debian.org/debian jessie Release: The following signatures were invalid: KEYEXPIRED 1587841717  KEYEXPIRED 1587841717  KEYEXPIRED 1587841717  KEYEXPIRED 1587841717  KEYEXPIRED 1587841717
W: The repository 'http://archive.debian.org/debian jessie Release' is not signed.
+ mkdir -p -m 777 /qemu/powerpc
+ cd /qemu/powerpc
+ apt-get -d --no-install-recommends download busybox:powerpc dropbear:powerpc libc6:powerpc libgcc1:powerpc libstdc++6:powerpc linux-image-4.9.0-0.bpo.6-powerpc:powerpc ncurses-base zlib1g:powerpc
WARNING: The following packages cannot be authenticated!
  dropbear:powerpc
E: Some packages could not be authenticated
The command '/bin/sh -c /linux-image.sh powerpc' returned a non-zero code: 100

PowerPC seems not to have long term support for powerpc:
https://www.debian.org/releases/jessie/

The problem is that the keys which signed the powerpc packages have
expired so they will always fail package verification. Disabling
signature verification will get around that but has obvious security
concerns.
---
 docker/linux-image.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docker/linux-image.sh b/docker/linux-image.sh
index 449573e02..5e8418bcb 100755
--- a/docker/linux-image.sh
+++ b/docker/linux-image.sh
@@ -47,6 +47,7 @@ main() {
 
             # archive.debian.org Release files are expired.
             echo "Acquire::Check-Valid-Until false;" | tee -a /etc/apt/apt.conf.d/10-nocheckvalid
+            echo "APT::Get::AllowUnauthenticated true;" | tee -a /etc/apt/apt.conf.d/10-nocheckvalid
 
             dropbear="dropbear"
             ;;