-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
57 lines (45 loc) · 1.76 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
ARG RUSTVERSION=1.84
ARG DEBIANVERSION=bullseye
FROM --platform=$BUILDPLATFORM rust:${RUSTVERSION}-${DEBIANVERSION} AS builder
ARG BUILDARCH
ARG TARGETARCH
ARG TARGETOS
# Store info about target triplet
RUN arch=$(echo ${TARGETARCH} | sed 's/arm64/aarch64/g' | sed 's/amd64/x86_64/g') \
&& vendor=unknown \
&& os="$(echo ${TARGETOS} | tr '[:upper:]' '[:lower:]')" \
&& abi=gnu \
&& target="$arch-$vendor-$os-$abi" \
&& echo "$arch" > /tmp/y-lang-rust-target-arch \
&& echo "$os" > /tmp/y-lang-rust-target-os \
&& echo "$abi" > /tmp/y-lang-rust-target-abi \
&& echo "$target" > /tmp/y-lang-rust-target
# Install the cross buildtools if needed (this most importantly contains the proper linker!)
RUN if [ ${BUILDARCH} != ${TARGETARCH} ]; then \
apt-get update -y && apt-get install -y crossbuild-essential-$TARGETARCH; \
fi
# Install the target toolchain
RUN target="$(cat /tmp/y-lang-rust-target)" \
&& rustup target add "$target"
# Copy the sources
WORKDIR /opt/y-lang
COPY src src
COPY lib lib
COPY test-utils test-utils
COPY Cargo.toml Cargo.lock .
# Build the `why` compiler (and make sure that cargo knows about the correct linker)
RUN arch="$(cat /tmp/y-lang-rust-target-arch)" \
&& os="$(cat /tmp/y-lang-rust-target-os)" \
&& abi="$(cat /tmp/y-lang-rust-target-abi)" \
&& target="$(cat /tmp/y-lang-rust-target)" \
&& target_linker="$arch-$os-$abi-gcc" \
&& cargo build --release --target "$target" --config "target.$target.linker=\"$target_linker\"" \
&& mkdir -p bin \
&& cp target/"$target"/release/why bin
ARG DEBIANVERSION
FROM debian:${DEBIANVERSION}-slim
# Install runtime dependencies
RUN apt-get update -y && apt-get install -y nasm
# Copy the compiler
COPY --from=builder /opt/y-lang/bin/why /usr/local/bin/why
ENTRYPOINT ["/usr/local/bin/why"]