Skip to content

Commit

Permalink
Merge pull request #4 from eduardo010174/main
Browse files Browse the repository at this point in the history
Add github action and Reduce docker image
  • Loading branch information
joaovarelas authored Dec 31, 2023
2 parents 92ba913 + 251a765 commit 64759e2
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 34 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker build image on release

on:
push:
branches:
- 'main'

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Set repo name lowercase
id: repo
uses: ASzc/change-string-case-action@v2
with:
string: ${{ github.repository }}
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ steps.repo.outputs.lowercase }}:latest
124 changes: 90 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,124 @@
FROM rust:1.70.0-bullseye

FROM debian:bullseye-slim as builder-llvm

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
# install dependencies
RUN apt update -y
RUN apt install -y cmake ninja-build libc6 libc6-dev git gcc clang-11 python3 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
RUN apt update -y &&\
apt install --no-install-recommends -y \
cmake \
ninja-build \
libc6 libc6-dev \
git \
gcc \
g++ \
clang-11 \
python3 \
gcc-mingw-w64-x86-64 \
g++-mingw-w64-x86-64 \
ca-certificates \
curl \
pkg-config \
libstdc++6 \
libssl-dev

# get source code for rust-llvm, rust compiler and hikari OLLVM
WORKDIR /repos

RUN git clone --single-branch --branch 1.70.0 --depth 1 https://github.com/rust-lang/rust rust-1.70.0
RUN git clone --single-branch --branch rustc/16.0-2023-03-06 --depth 1 https://github.com/rust-lang/llvm-project llvm-16.0-2023-03-06
#RUN git clone --single-branch --branch llvm-16.0.0rel --recursive --depth 1 https://github.com/61bcdefg/Hikari-LLVM15 ollvm-16.0
COPY ollvm16.patch /repos/ollvm16.patch
#RUN git clone --single-branch --branch llvm-16.0.0rel --recursive --depth 1 https://github.com/61bcdefg/Hikari-LLVM15 ollvm-16.0
RUN git clone --single-branch --branch rustc/16.0-2023-03-06 --depth 1 https://github.com/rust-lang/llvm-project /repos/llvm-16.0-2023-03-06 &&\
cd /repos/llvm-16.0-2023-03-06/ &&\
git apply --reject --ignore-whitespace ../ollvm16.patch

# apply the OLLVM patch to LLVM to add obfuscation passes
WORKDIR /repos/llvm-16.0-2023-03-06/
RUN git apply --reject --ignore-whitespace ../ollvm16.patch
RUN find . -name "*.rej"
#RUN find . -name "*.rej"

WORKDIR /repos/llvm-16.0-2023-03-06/
# build custom LLVM
RUN mkdir build
WORKDIR /repos/llvm-16.0-2023-03-06/build/
RUN cmake -G "Ninja" ../llvm -DCMAKE_INSTALL_PREFIX="./llvm_x64" -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld;" -DLLVM_TARGETS_TO_BUILD="X86" -DBUILD_SHARED_LIBS=ON -DLLVM_INSTALL_UTILS=ON -DLLVM_INCLUDE_TESTS=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_BUILD_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_ENABLE_BACKTRACES=OFF -DLLVM_BUILD_DOCS=OFF -DBUILD_SHARED_LIBS=OFF

RUN cmake --build . -j8
RUN cmake --install .

RUN mkdir build &&\
cd build/ &&\
cmake -G "Ninja" ../llvm \
-DCMAKE_INSTALL_PREFIX="./llvm_x64" \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld;" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_BUILD_TESTS=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_BUILD_BENCHMARKS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_ENABLE_BACKTRACES=OFF \
-DLLVM_BUILD_DOCS=OFF \
-DBUILD_SHARED_LIBS=OFF

RUN cd build/ &&\
cmake --build . -j$(nproc)

RUN cd build/ &&\
cmake --install .



FROM rust:1.70.0-bullseye as builder-rustc

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

RUN apt update -y &&\
apt install --no-install-recommends -y \
cmake \
ninja-build \
libc6 libc6-dev \
git \
gcc \
g++ \
clang-11 \
python3 \
gcc-mingw-w64-x86-64 \
g++-mingw-w64-x86-64 \
ca-certificates \
curl \
pkg-config \
libstdc++6 \
libssl-dev

COPY --from=builder-llvm /repos/llvm-16.0-2023-03-06/build/llvm_x64 /repos/llvm-16.0-2023-03-06/build

# check if llvm was built
RUN /repos/llvm-16.0-2023-03-06/build/bin/llvm-config --version

RUN git clone --single-branch --branch 1.70.0 --depth 1 https://github.com/rust-lang/rust /repos/rust-1.70.0

# config rust compiler
# https://rustc-dev-guide.rust-lang.org/building/new-target.html#using-pre-built-llvm
WORKDIR /repos/rust-1.70.0/
RUN cp config.example.toml config.toml

RUN sed -i 's/#debug = false/debug = false/' config.toml
RUN sed -i 's/#channel = "dev"/channel = "nightly"/' config.toml
RUN sed -i 's/#llvm-config = <none> (path)/llvm-config = "\/repos\/llvm-16.0-2023-03-06\/build\/bin\/llvm-config"/' config.toml
RUN sed -i 's/#target = build.host (list of triples)/target = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-gnu"]/' config.toml

RUN cp config.example.toml config.toml &&\
sed -i 's/#debug = false/debug = false/' config.toml &&\
sed -i 's/#channel = "dev"/channel = "nightly"/' config.toml &&\
sed -i 's/#llvm-config = <none> (path)/llvm-config = "\/repos\/llvm-16.0-2023-03-06\/build\/bin\/llvm-config"/' config.toml &&\
sed -i 's/#llvm-filecheck = "\/path\/to\/llvm-version\/bin\/FileCheck"/llvm-filecheck = "\/repos\/llvm-16.0-2023-03-06\/build\/bin\/FileCheck"/' config.toml &&\
sed -i 's/#target = build.host (list of triples)/target = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-gnu"]/' config.toml

# build rust compiler
RUN python3 x.py build
RUN python3 x.py build --target x86_64-pc-windows-gnu
RUN python3 x.py build --target x86_64-unknown-linux-gnu,x86_64-pc-windows-gnu

# build cargo
#RUN python3 x.py build tools/cargo


# check toolchains
RUN rustup toolchain list --verbose


# rustup to configure nightly and install
WORKDIR /repos/

COPY rustup.sh /repos/rustup.sh
RUN chmod +x rustup.sh
RUN bash rustup.sh

# check toolchains
RUN rustup toolchain list --verbose

# rustup link our custom OLLVM toolchain, make it default
RUN rustup toolchain link ollvm-rust-1.70.0 /repos/rust-1.70.0/build/x86_64-unknown-linux-gnu/stage1/
RUN rustup default ollvm-rust-1.70.0
RUN rustup toolchain link ollvm-rust-1.70.0 /repos/rust-1.70.0/build/x86_64-unknown-linux-gnu/stage1/ &&\
rustup default ollvm-rust-1.70.0


# Example compilation flags, use volumes to pass cargo packages into container
Expand Down

0 comments on commit 64759e2

Please sign in to comment.