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

Commit

Permalink
Merge pull request #537 from kazk/fix/rust-rustflags
Browse files Browse the repository at this point in the history
[Rust] Avoid crates to be recompiled
  • Loading branch information
jhoffner authored Nov 1, 2017
2 parents abcc9fe + 624510f commit dbf943d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
36 changes: 20 additions & 16 deletions docker/rust.docker
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM codewars/base-runner

RUN ln -s /home/codewarrior /workspace

COPY frameworks/rust/skeleton /workspace/rust
RUN chown -R codewarrior:codewarrior /workspace/rust

USER codewarrior
ENV USER=codewarrior HOME=/home/codewarrior
# based on the Dockerfile for https://hub.docker.com/_/rust/
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain 1.15.1; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME;

# Install rustup with the Rust v1.15.1 toolchain
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.15.1
# ~/.cargo/env
ENV PATH $HOME/.cargo/bin:$PATH
RUN cd /workspace/rust && cargo build && rm src/lib.rs

USER root
RUN ln -s /home/codewarrior /workspace
ENV NPM_CONFIG_LOGLEVEL warn

WORKDIR /runner
Expand All @@ -33,9 +26,20 @@ COPY test/runners/rust_spec.js test/runners/
COPY entrypoint.sh entrypoint.sh
RUN chmod +x entrypoint.sh

COPY frameworks/rust/skeleton /workspace/rust
RUN chown -R codewarrior:codewarrior /workspace/rust

USER codewarrior
ENV USER=codewarrior HOME=/home/codewarrior
ENV PATH=$HOME/.cargo/bin:$PATH
ENV USER=codewarrior \
HOME=/home/codewarrior \
# set RUSTFLAGS (for backward compatibility) here
# compiling with different RUSTFLAGS for submitted solution causes downloaded crates to be recompiled
RUSTFLAGS='-Adead_code -Aunused_imports -Aunused_variables -Anon_snake_case'
# download and compile crates
RUN set -ex; \
cd /workspace/rust; \
cargo build; \
rm src/lib.rs

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

Expand Down
17 changes: 0 additions & 17 deletions lib/runners/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
args: ['run'],
options: {
cwd: '/workspace/rust',
env: Object.assign({}, process.env, {
RUSTFLAGS: rustFlags(),
}),
},
});
},
Expand Down Expand Up @@ -44,9 +41,6 @@ module.exports = {
args: ['test'],
options: {
cwd: '/workspace/rust',
env: Object.assign({}, process.env, {
RUSTFLAGS: rustFlags(),
}),
},
});
},
Expand Down Expand Up @@ -106,14 +100,3 @@ module.exports = {
return stderr;
},
};

// ignore some warnings for backward compatibility
function rustFlags() {
const flags = [];
if (process.env.RUSTFLAGS !== '') flags.push(process.env.RUSTFLAGS);
flags.push('-A', 'dead_code');
flags.push('-A', 'unused_imports');
flags.push('-A', 'unused_variables');
flags.push('-A', 'non_snake_case');
return flags.join(' ');
}

0 comments on commit dbf943d

Please sign in to comment.