Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: init c2rust script #4564

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions bindings/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ incremental = false
lto = true
codegen-units = 1
incremental = false

[profile.fuzz]
inherits = "dev"
opt-level = 3
incremental = false
codegen-units = 1
2 changes: 1 addition & 1 deletion crypto/s2n_certificate.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct s2n_cert_chain_and_key {
void *context;
};

struct certs_by_type {
struct s2n_certs_by_type {
struct s2n_cert_chain_and_key *certs[S2N_CERT_TYPE_COUNT];
};

Expand Down
5 changes: 5 additions & 0 deletions error/s2n_errno.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ void s2n_debug_info_reset(void)
_s2n_debug_info.source = "";
}

void _s2n_debug_info_set(struct s2n_debug_info debug_info)
{
_s2n_debug_info = debug_info;
}

#ifdef S2N_STACKTRACE

#define MAX_BACKTRACE_DEPTH 20
Expand Down
4 changes: 4 additions & 0 deletions error/s2n_errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ struct s2n_debug_info {
};

extern __thread struct s2n_debug_info _s2n_debug_info;
void _s2n_debug_info_set(struct s2n_debug_info debug_info);

#define S2N_ERRNO_GET() s2n_errno
#define S2N_ERRNO_SET(v) do { s2n_errno = v; } while (0)

#define TO_STRING(s) #s
#define STRING_(s) TO_STRING(s)
Expand Down
2 changes: 2 additions & 0 deletions scripts/s2n2rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/s2n-tls
/target
76 changes: 76 additions & 0 deletions scripts/s2n2rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
FROM ubuntu:bionic as c2rustsrc

ARG c2rust=9511a4f28d18d626a9b9d6fc73596f60e51e2cf7

RUN \
set -ex; \
apt-get update; \
apt-get install curl unzip -y; \
cd /opt/; \
curl https://github.com/immunant/c2rust/archive/${c2rust}.zip -L -o c2rust.zip; \
unzip c2rust.zip; \
rm c2rust.zip; \
mv c2rust-${c2rust} c2rust; \
echo done

FROM ubuntu:bionic

ARG USER=s2n
ARG UID=1000
ARG GID=1000
ENV HOME=/home/$USER
ENV DEBIAN_FRONTEND=noninteractive

USER root
RUN groupadd -f -g $GID ${USER}
RUN useradd --create-home -u $UID -g $GID --create-home --shell /bin/bash ${USER}

# /home/$USER needs to be accessible by other users because we always run the
# cargo binary from /home/$USER/.cargo/bin
RUN chmod 755 /home/${USER}

COPY --chown=${USER}:${USER} --from=c2rustsrc /opt/c2rust /home/${USER}/c2rust

RUN \
set -ex; \
bash /home/${USER}/c2rust/scripts/provision_deb.sh; \
chown ${USER}:${USER} -R /home/${USER}; \
chmod 755 -R /home/${USER}/c2rust; \
echo done

USER $USER

ENV HOME=/home/$USER
ARG RUST_VER=nightly-2024-05-19
ENV RUST_VER=${RUST_VER}
WORKDIR /home/$USER

# setup rust
RUN \
set -ex; \
cd $HOME/c2rust; \
./scripts/provision_rust.sh; \
echo ". $HOME/.cargo/env" >> $HOME/.bashrc; \
echo done

# install dependencies
RUN \
set -ex; \
. "$HOME/.cargo/env"; \
rustup component add rust-analyzer; \
cargo install bindgen-cli; \
echo done

RUN \
set -ex; \
. "$HOME/.cargo/env"; \
cd $HOME/c2rust; \
cargo build --release; \
echo "export PATH=\"$HOME/c2rust/target/release:\$PATH\"" >> $HOME/.bashrc; \
echo done

COPY --chmod=766 entrypoint.sh /bin/s2n2rust

SHELL ["/bin/bash"]
ENTRYPOINT ["/bin/s2n2rust"]

10 changes: 10 additions & 0 deletions scripts/s2n2rust/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -ex

. "$HOME/.cargo/env"
export PATH="$HOME/c2rust/target/release:$PATH"

cargo install --path $2/scripts/s2n2rust/s2n2rust

exec $HOME/.cargo/bin/s2n2rust $@
35 changes: 35 additions & 0 deletions scripts/s2n2rust/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -ex

IMAGE=aws/s2n-tls-2rust
C2RUST_COMMIT=9511a4f28d18d626a9b9d6fc73596f60e51e2cf7
SCRIPT_DIR=$( cd "$( dirname $0 )" && pwd )
S2N_TLS="$(dirname "$SCRIPT_DIR")/../"

BUILD_ARGS=(
"--file $SCRIPT_DIR/Dockerfile"
"--tag $IMAGE"
"--build-arg=c2rust=$C2RUST_COMMIT"
"--build-arg=USER=$USER"
"--build-arg=UID=$UID"
# "--build-arg=GID=$GID"
)

sudo DOCKER_BUILDKIT=1 docker build $SCRIPT_DIR ${BUILD_ARGS[@]}

docker_run() {
sudo docker run \
-i \
--rm \
--tty \
--volume $S2N_TLS:/home/$USER/s2n-tls \
--user $USER \
$IMAGE \
$@
}

docker_run transpile /home/$USER/s2n-tls
docker_run refactor /home/$USER/s2n-tls

echo "build available in $SCRIPT_DIR/target/s2n-tls"
1 change: 1 addition & 0 deletions scripts/s2n2rust/s2n2rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading
Loading