Skip to content

Commit 4b2c82a

Browse files
vibhorgupta-ghchampionswimmer
authored andcommitted
Rust support (#31)
* rust support * added test * readme
1 parent 774790d commit 4b2c82a

File tree

8 files changed

+74
-0
lines changed

8 files changed

+74
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ Currently we have following images -
2929
- [py2](containers/py2)
3030
- [py3](containers/py3)
3131
- [ruby](containers/ruby)
32+
- [rust](containers/rust)

containers/rust/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM alpine:3.6
2+
3+
RUN apk add --no-cache musl-dev bash rust="1.17.0-r2"
4+
5+
COPY ./compile.sh /bin/compile.sh
6+
COPY ./run.sh /bin/run.sh
7+
8+
RUN chmod 777 /bin/compile.sh; \
9+
chmod 777 /bin/run.sh

containers/rust/compile.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
rustc script.rs 2> compile.stderr 1> compile.stdout

containers/rust/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
chmod 777 script.rs
4+
./script < run.stdin 1> run.stdout 2> run.stderr

test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@
3939
@test "test ruby" {
4040
bash tests/ruby/test_worker.sh
4141
}
42+
43+
@test "test rust" {
44+
bash tests/rust/test_worker.sh
45+
}

tests/rust/run.stdin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
World

tests/rust/script.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::io;
2+
3+
fn main() {
4+
let mut input = String::new();
5+
6+
io::stdin().read_line(&mut input)
7+
.ok()
8+
.expect("Couldn't read line");
9+
10+
println!("Hello {}", input);
11+
}

tests/rust/test_worker.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
pushd $(dirname "$0")
3+
DIR=$(pwd)
4+
RUNBOX="${DIR}/runbox"
5+
6+
echo $RUNBOX
7+
# Remove RUNBOX
8+
rm -rf $RUNBOX
9+
10+
# Create runbox
11+
mkdir -p $RUNBOX
12+
13+
# Copy source to runbox
14+
cp $DIR/script.rs $RUNBOX/script.rs
15+
cp $DIR/run.stdin $RUNBOX/run.stdin
16+
17+
# Test Compile
18+
docker run \
19+
--cpus="1" \
20+
--memory="100m" \
21+
--ulimit nofile=64:64 \
22+
--rm \
23+
--read-only \
24+
-v "$RUNBOX":/usr/src/runbox \
25+
-v "$RUNBOX":/tmp \
26+
-w /usr/src/runbox codingblocks/judge-worker-rust \
27+
bash -c "/bin/compile.sh && /bin/run.sh"
28+
29+
ls -lh ${RUNBOX}
30+
31+
expected="Hello World"
32+
actual="$(cat ${RUNBOX}/run.stdout)"
33+
if [ "$expected" == "$actual" ] ;then
34+
:
35+
else
36+
echo "MISMATCH: Expected = $expected; Actual = $actual"
37+
exit 1
38+
fi
39+
40+
# Delete runbox
41+
rm -rf $RUNBOX

0 commit comments

Comments
 (0)