Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit dbf943d

Browse files
authored
Merge pull request #537 from kazk/fix/rust-rustflags
[Rust] Avoid crates to be recompiled
2 parents abcc9fe + 624510f commit dbf943d

File tree

2 files changed

+20
-33
lines changed

2 files changed

+20
-33
lines changed

docker/rust.docker

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
FROM codewars/base-runner
22

3-
RUN ln -s /home/codewarrior /workspace
4-
5-
COPY frameworks/rust/skeleton /workspace/rust
6-
RUN chown -R codewarrior:codewarrior /workspace/rust
7-
8-
USER codewarrior
9-
ENV USER=codewarrior HOME=/home/codewarrior
3+
# based on the Dockerfile for https://hub.docker.com/_/rust/
4+
ENV RUSTUP_HOME=/usr/local/rustup \
5+
CARGO_HOME=/usr/local/cargo \
6+
PATH=/usr/local/cargo/bin:$PATH
7+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain 1.15.1; \
8+
chmod -R a+w $RUSTUP_HOME $CARGO_HOME;
109

11-
# Install rustup with the Rust v1.15.1 toolchain
12-
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.15.1
13-
# ~/.cargo/env
14-
ENV PATH $HOME/.cargo/bin:$PATH
15-
RUN cd /workspace/rust && cargo build && rm src/lib.rs
16-
17-
USER root
10+
RUN ln -s /home/codewarrior /workspace
1811
ENV NPM_CONFIG_LOGLEVEL warn
1912

2013
WORKDIR /runner
@@ -33,9 +26,20 @@ COPY test/runners/rust_spec.js test/runners/
3326
COPY entrypoint.sh entrypoint.sh
3427
RUN chmod +x entrypoint.sh
3528

29+
COPY frameworks/rust/skeleton /workspace/rust
30+
RUN chown -R codewarrior:codewarrior /workspace/rust
31+
3632
USER codewarrior
37-
ENV USER=codewarrior HOME=/home/codewarrior
38-
ENV PATH=$HOME/.cargo/bin:$PATH
33+
ENV USER=codewarrior \
34+
HOME=/home/codewarrior \
35+
# set RUSTFLAGS (for backward compatibility) here
36+
# compiling with different RUSTFLAGS for submitted solution causes downloaded crates to be recompiled
37+
RUSTFLAGS='-Adead_code -Aunused_imports -Aunused_variables -Anon_snake_case'
38+
# download and compile crates
39+
RUN set -ex; \
40+
cd /workspace/rust; \
41+
cargo build; \
42+
rm src/lib.rs
3943

4044
RUN mocha -t 10000 test/runners/rust_spec.js
4145

lib/runners/rust.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ module.exports = {
1111
args: ['run'],
1212
options: {
1313
cwd: '/workspace/rust',
14-
env: Object.assign({}, process.env, {
15-
RUSTFLAGS: rustFlags(),
16-
}),
1714
},
1815
});
1916
},
@@ -44,9 +41,6 @@ module.exports = {
4441
args: ['test'],
4542
options: {
4643
cwd: '/workspace/rust',
47-
env: Object.assign({}, process.env, {
48-
RUSTFLAGS: rustFlags(),
49-
}),
5044
},
5145
});
5246
},
@@ -106,14 +100,3 @@ module.exports = {
106100
return stderr;
107101
},
108102
};
109-
110-
// ignore some warnings for backward compatibility
111-
function rustFlags() {
112-
const flags = [];
113-
if (process.env.RUSTFLAGS !== '') flags.push(process.env.RUSTFLAGS);
114-
flags.push('-A', 'dead_code');
115-
flags.push('-A', 'unused_imports');
116-
flags.push('-A', 'unused_variables');
117-
flags.push('-A', 'non_snake_case');
118-
return flags.join(' ');
119-
}

0 commit comments

Comments
 (0)