Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions src/usr/local/buildpack/tools/rust.sh

This file was deleted.

44 changes: 44 additions & 0 deletions src/usr/local/buildpack/tools/v2/rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

function prepare_tool() {
create_tool_path
export_env RUST_BACKTRACE 1
export_env CARGO_HOME "${USER_HOME}/.cargo"
export_path "\$CARGO_HOME/bin"
}

function install_tool () {
local versioned_tool_path
local file
local arch=x86_64
local tool_path
tool_path=$(find_tool_path)

if [[ ! -d "${tool_path}" ]]; then
if [[ $(is_root) -ne 0 ]]; then
echo "${TOOL_NAME} not prepared"
exit 1
fi
prepare_tool
tool_path=$(find_tool_path)
fi

versioned_tool_path=$(create_versioned_tool_path)

file=$(get_from_url "https://static.rust-lang.org/dist/rust-${TOOL_VERSION}-${arch}-unknown-linux-gnu.tar.gz")
mkdir -p "${TEMP_DIR}/rust"
bsdtar --strip 1 -C "${TEMP_DIR}/rust" -xf "${file}"
"${TEMP_DIR}/rust/install.sh" --prefix="$versioned_tool_path" --components=cargo,rust-std-${arch}-unknown-linux-gnu,rustc
rm -rf "${TEMP_DIR}/rust"
}

function link_tool () {
local versioned_tool_path
versioned_tool_path=$(find_versioned_tool_path)

shell_wrapper "cargo" "${versioned_tool_path}/bin"
shell_wrapper "rustc" "${versioned_tool_path}/bin"

cargo --version
rustc --version
}
50 changes: 46 additions & 4 deletions test/rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
ARG IMAGE=containerbase/buildpack
FROM ${IMAGE} as build
ARG BUILDPACK_DEBUG

ARG APT_HTTP_PROXY
FROM ${IMAGE} as base

RUN touch /.dummy

COPY --chown=1000:0 test test

WORKDIR /test

ARG BUILDPACK_DEBUG

RUN prepare-tool rust

FROM base as build
ARG BUILDPACK_DEBUG

# renovate: datasource=docker versioning=docker
RUN install-tool rust 1.65.0

# renovate: datasource=docker versioning=docker
RUN install-tool rust 1.65.0

COPY --chown=1000:0 test test

WORKDIR /test
USER 1000

#--------------------------------------
# test a: root
#--------------------------------------
FROM build as testa

RUN set -ex; \
cd a; \
cargo update; \
cargo update --manifest-path Cargo.toml --package serde;

SHELL [ "/bin/sh", "-c" ]
RUN rustc --version
RUN cargo --version

#--------------------------------------
# test b: non-root
#--------------------------------------
FROM base as testb
ARG BUILDPACK_DEBUG

USER 1000

# renovate: datasource=docker versioning=docker
RUN install-tool rust 1.65.0

RUN set -ex; \
cd a; \
Expand All @@ -24,3 +58,11 @@ RUN set -ex; \
SHELL [ "/bin/sh", "-c" ]
RUN rustc --version
RUN cargo --version

#--------------------------------------
# final
#--------------------------------------
FROM base

COPY --from=testa /.dummy /.dummy
COPY --from=testb /.dummy /.dummy