From 6f8dc902231cd3980661b7dae6be0171a30058dd Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Wed, 1 Aug 2018 19:11:18 +0530 Subject: [PATCH 1/3] rust support --- containers/rust/Dockerfile | 9 +++++++++ containers/rust/compile.sh | 3 +++ containers/rust/run.sh | 4 ++++ tests/rust/run.stdin | 1 + tests/rust/script.rs | 11 ++++++++++ tests/rust/test_worker.sh | 41 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 containers/rust/Dockerfile create mode 100644 containers/rust/compile.sh create mode 100644 containers/rust/run.sh create mode 100644 tests/rust/run.stdin create mode 100644 tests/rust/script.rs create mode 100644 tests/rust/test_worker.sh diff --git a/containers/rust/Dockerfile b/containers/rust/Dockerfile new file mode 100644 index 0000000..3022f43 --- /dev/null +++ b/containers/rust/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +RUN apk add --no-cache musl-dev bash rust="1.17.0-r2" + +COPY ./compile.sh /bin/compile.sh +COPY ./run.sh /bin/run.sh + +RUN chmod 777 /bin/compile.sh; \ + chmod 777 /bin/run.sh diff --git a/containers/rust/compile.sh b/containers/rust/compile.sh new file mode 100644 index 0000000..035348e --- /dev/null +++ b/containers/rust/compile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +rustc script.rs 2> compile.stderr 1> compile.stdout diff --git a/containers/rust/run.sh b/containers/rust/run.sh new file mode 100644 index 0000000..7878268 --- /dev/null +++ b/containers/rust/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +chmod 777 script.rs +./script < run.stdin 1> run.stdout 2> run.stderr diff --git a/tests/rust/run.stdin b/tests/rust/run.stdin new file mode 100644 index 0000000..216e97c --- /dev/null +++ b/tests/rust/run.stdin @@ -0,0 +1 @@ +World diff --git a/tests/rust/script.rs b/tests/rust/script.rs new file mode 100644 index 0000000..c56b158 --- /dev/null +++ b/tests/rust/script.rs @@ -0,0 +1,11 @@ +use std::io; + +fn main() { + let mut input = String::new(); + + io::stdin().read_line(&mut input) + .ok() + .expect("Couldn't read line"); + + println!("Hello {}", input); +} diff --git a/tests/rust/test_worker.sh b/tests/rust/test_worker.sh new file mode 100644 index 0000000..7369d6d --- /dev/null +++ b/tests/rust/test_worker.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Remove RUNBOX +rm -rf $RUNBOX + +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp $DIR/script.rs $RUNBOX/script.rs +cp $DIR/run.stdin $RUNBOX/run.stdin + +# Test Compile +docker run \ + --cpus="1" \ + --memory="100m" \ + --ulimit nofile=64:64 \ + --rm \ + --read-only \ + -v "$RUNBOX":/usr/src/runbox \ + -v "$RUNBOX":/tmp \ + -w /usr/src/runbox rust \ + bash -c "/bin/compile.sh && /bin/run.sh" + +ls -lh ${RUNBOX} + +expected="Hello World" +actual="$(cat ${RUNBOX}/run.stdout)" +if [ "$expected" == "$actual" ] ;then + : +else + echo "MISMATCH: Expected = $expected; Actual = $actual" + exit 1 +fi + +# Delete runbox +rm -rf $RUNBOX From 64c6016a1626b2d142fb7f5b62d8db8d37cbea1f Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Wed, 1 Aug 2018 19:14:25 +0530 Subject: [PATCH 2/3] added test --- test.sh | 4 ++++ tests/rust/test_worker.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 32ff951..037e326 100755 --- a/test.sh +++ b/test.sh @@ -39,3 +39,7 @@ @test "test ruby" { bash tests/ruby/test_worker.sh } + +@test "test rust" { + bash tests/rust/test_worker.sh +} diff --git a/tests/rust/test_worker.sh b/tests/rust/test_worker.sh index 7369d6d..78904fe 100644 --- a/tests/rust/test_worker.sh +++ b/tests/rust/test_worker.sh @@ -23,7 +23,7 @@ docker run \ --read-only \ -v "$RUNBOX":/usr/src/runbox \ -v "$RUNBOX":/tmp \ - -w /usr/src/runbox rust \ + -w /usr/src/runbox codingblocks/judge-worker-rust \ bash -c "/bin/compile.sh && /bin/run.sh" ls -lh ${RUNBOX} From 9b567326fc289cab9faccd808cf3d9497690ba53 Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Wed, 1 Aug 2018 19:17:49 +0530 Subject: [PATCH 3/3] readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 434e2ca..9ddc0e7 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,4 @@ Currently we have following images - - [py2](containers/py2) - [py3](containers/py3) - [ruby](containers/ruby) + - [rust](containers/rust)