From 70293a98ae51b0e180e97cbe43f68643b7b4c6d1 Mon Sep 17 00:00:00 2001 From: Masashi Yoshimura Date: Sat, 13 Jan 2024 03:12:01 +0900 Subject: [PATCH 1/5] Create tests.yml --- .github/workflows/tests.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a680897 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,27 @@ +name: Test + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build-and-test: + runs-on: ubuntu-22.04 + name: Build-and-Run + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: build container image + run: docker build . -t elfconv-image + + - name: run container and build elfconv + run: | + docker run -d --name elfconv-container elfconv-image + docker exec elfconv-container /bin/bash -c "source ~/.bash_profile && ./build.sh" + + - name: elfconv integration test + run: | + docker exec elfconv-container /bin/bash -c "ctest" From f4705cb0ba50f43efba91c09e016ca20e0e6f1a3 Mon Sep 17 00:00:00 2001 From: yomaytk Date: Sun, 14 Jan 2024 23:20:58 +0900 Subject: [PATCH 2/5] Add x86_64 support of container. --- Dockerfile | 15 ++++++++++----- examples/eratosthenes_sieve/Makefile | 9 ++++++++- examples/hello/Makefile | 9 ++++++++- examples/linpack/Makefile | 12 ++++++++---- examples/print_hello/Makefile | 9 ++++++++- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b82e22..2b5923b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ # Choose your LLVM version (16+) ARG LLVM_VERSION=16 -ARG ARCH=aarch64 ARG UBUNTU_VERSION=22.04 ARG DISTRO_NAME=jammy ARG ROOT_DIR=/root/elfconv @@ -8,13 +7,11 @@ ARG ROOT_DIR=/root/elfconv # Run-time dependencies go here FROM ubuntu:${UBUNTU_VERSION} ARG LLVM_VERSION -ARG ARCH ARG UBUNTU_VERSION ARG DISTRO_NAME ARG ROOT_DIR RUN date -RUN dpkg --add-architecture armhf RUN apt update RUN apt install -qqy --no-install-recommends apt-transport-https software-properties-common gnupg ca-certificates wget && \ @@ -31,12 +28,20 @@ echo "deb-src http://apt.llvm.org/${DISTRO_NAME}/ llvm-toolchain-${DISTRO_NAME}- # several install RUN apt update -RUN apt install -qqy --no-install-recommends libtinfo-dev libzstd-dev python3-pip python3-setuptools python-setuptools python3 build-essential \ - clang-${LLVM_VERSION} lld-${LLVM_VERSION} libstdc++-*-dev-armhf-cross ninja-build pixz xz-utils make rpm curl unzip tar git zip pkg-config vim \ +RUN apt install -qqy --no-install-recommends file libtinfo-dev libzstd-dev python3-pip python3-setuptools python-setuptools python3 build-essential \ + clang-${LLVM_VERSION} lld-${LLVM_VERSION} ninja-build pixz xz-utils make rpm curl unzip tar git zip pkg-config vim \ libc6-dev liblzma-dev zlib1g-dev libselinux1-dev libbsd-dev ccache binutils-dev libelf-dev && \ apt upgrade --yes && apt clean --yes && \ rm -rf /var/lib/apt/lists/* +# cross compile library +RUN apt update && \ + if [ "$( uname -m )" = "x86_64" ]; then \ + dpkg --add-architecture i386 && apt update && apt install -qqy zlib1g-dev:i386 gcc-multilib g++-multilib && apt update && apt install -qqy g++-*-aarch64-linux-gnu; \ + elif [ "$( uname -m )" = "aarch64" ]; then \ + dpkg --add-architecture armhf && apt update && apt install -qqy libstdc++-*-dev-armhf-cross; \ + fi + # emscripten install RUN cd /root && git clone https://github.com/emscripten-core/emsdk.git && cd emsdk && \ git pull && ./emsdk install latest && ./emsdk activate latest && . ./emsdk_env.sh && echo 'source "/root/emsdk/emsdk_env.sh"' >> /root/.bash_profile diff --git a/examples/eratosthenes_sieve/Makefile b/examples/eratosthenes_sieve/Makefile index b9b189d..967965d 100644 --- a/examples/eratosthenes_sieve/Makefile +++ b/examples/eratosthenes_sieve/Makefile @@ -1,7 +1,14 @@ CC=clang-16 eratosthenes_sieve: start.s cal.c - $(CC) -nostdlib -static start.s cal.c + @ARCH=$$( uname -m ); \ + if [ "$$ARCH" = "x86_64" ]; then \ + $(CC) -nostdlib -static --target=aarch64-linux-gnu --gcc-toolchain=/usr --sysroot=/usr/aarch64-linux-gnu start.s cal.c -fuse-ld=lld -pthread; \ + elif [ "$$ARCH" = "aarch64" ]; then \ + $(CC) -nostdlib -static start.s cal.c; \ + else \ + echo "Unknown architecture"; exit 1; \ + fi clean: rm a.out diff --git a/examples/hello/Makefile b/examples/hello/Makefile index 4c87725..61ad8a1 100644 --- a/examples/hello/Makefile +++ b/examples/hello/Makefile @@ -1,7 +1,14 @@ CC=clang-16 hello: hello.c - $(CC) -static hello.c + @ARCH=$$( uname -m ); \ + if [ "$$ARCH" = "x86_64" ]; then \ + $(CC) -static --target=aarch64-linux-gnu --gcc-toolchain=/usr --sysroot=/usr/aarch64-linux-gnu hello.c -fuse-ld=lld -pthread; \ + elif [ "$$ARCH" = "aarch64" ]; then \ + $(CC) -static hello.c; \ + else \ + echo "Unknown architecture"; exit 1; \ + fi clean: rm a.out diff --git a/examples/linpack/Makefile b/examples/linpack/Makefile index 9e4bbb7..4041de8 100644 --- a/examples/linpack/Makefile +++ b/examples/linpack/Makefile @@ -2,11 +2,15 @@ CC=clang-16 -linpack-soft-float: nostdin_linpack.c - $(CC) -static nostdin_linpack.c -o a.soft-float.out - linpack: nostdin_linpack.c - $(CC) -static nostdin_linpack.c -o a.out + @ARCH=$$(uname -m); \ + if [ "$$ARCH" = "x86_64" ]; then \ + $(CC) -static --target=aarch64-linux-gnu --gcc-toolchain=/usr --sysroot=/usr/aarch64-linux-gnu nostdin_linpack.c -fuse-ld=lld -pthread; \ + elif [ "$$ARCH" = "aarch64" ]; then \ + $(CC) -static nostdin_linpack.c; \ + else \ + echo "Unknown architecture"; exit 1; \ + fi clean: rm *.out diff --git a/examples/print_hello/Makefile b/examples/print_hello/Makefile index 095922d..52e86db 100644 --- a/examples/print_hello/Makefile +++ b/examples/print_hello/Makefile @@ -1,7 +1,14 @@ CC=clang-16 print_hello: print_hello.c start.s - $(CC) -nostdlib -static print_hello.c start.s + @ARCH=$$( uname -m ); \ + if [ "$$ARCH" = "x86_64" ]; then \ + $(CC) -nostdlib -static --target=aarch64-linux-gnu --gcc-toolchain=/usr --sysroot=/usr/aarch64-linux-gnu start.s print_hello.c -fuse-ld=lld -pthread; \ + elif [ "$$ARCH" = "aarch64" ]; then \ + $(CC) -nostdlib -static start.s print_hello.c; \ + else \ + echo "Unknown architecture"; exit 1; \ + fi clean: rm a.out From c91017a1ddaef54a20e72101f779c0a7f0ed976e Mon Sep 17 00:00:00 2001 From: yomaytk Date: Sun, 14 Jan 2024 23:48:51 +0900 Subject: [PATCH 3/5] Fix tests.yml. --- .github/workflows/tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a680897..e9cc19f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,9 +17,12 @@ jobs: - name: build container image run: docker build . -t elfconv-image - - name: run container and build elfconv + - name: run container run: | docker run -d --name elfconv-container elfconv-image + + - name: build elfconv + run: | docker exec elfconv-container /bin/bash -c "source ~/.bash_profile && ./build.sh" - name: elfconv integration test From 138fe79b7427f8267a86e3ac8ce6934c82fc596c Mon Sep 17 00:00:00 2001 From: yomaytk Date: Mon, 15 Jan 2024 16:08:33 +0900 Subject: [PATCH 4/5] Fix scripts for container and tests.yml (succeed at least in aarch64.) --- .github/workflows/tests.yml | 15 +++------------ CMakeLists.txt | 2 ++ Dockerfile | 5 ++++- build.sh => scripts/build.sh | 2 +- scripts/container-entry-point.sh | 13 +++++++++++++ dev.sh => scripts/dev.sh | 0 6 files changed, 23 insertions(+), 14 deletions(-) rename build.sh => scripts/build.sh (99%) create mode 100755 scripts/container-entry-point.sh rename dev.sh => scripts/dev.sh (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e9cc19f..571f449 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,6 +6,7 @@ on: pull_request: branches: [ "main" ] +# ENTRYPOINT: `container-entry-point.sh` build and ctest jobs: build-and-test: runs-on: ubuntu-22.04 @@ -15,16 +16,6 @@ jobs: uses: actions/checkout@v4 - name: build container image - run: docker build . -t elfconv-image - - - name: run container - run: | - docker run -d --name elfconv-container elfconv-image - - - name: build elfconv - run: | - docker exec elfconv-container /bin/bash -c "source ~/.bash_profile && ./build.sh" - - - name: elfconv integration test run: | - docker exec elfconv-container /bin/bash -c "ctest" + docker build . -t elfconv-image + docker run --name elfconv-container elfconv-image diff --git a/CMakeLists.txt b/CMakeLists.txt index c8541c0..5197951 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +enable_testing() + cmake_minimum_required(VERSION 3.21) project(elfconv) diff --git a/Dockerfile b/Dockerfile index 2b5923b..c6c27b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,11 +46,14 @@ RUN apt update && \ RUN cd /root && git clone https://github.com/emscripten-core/emsdk.git && cd emsdk && \ git pull && ./emsdk install latest && ./emsdk activate latest && . ./emsdk_env.sh && echo 'source "/root/emsdk/emsdk_env.sh"' >> /root/.bash_profile -# wasmedge install +# WASI Runtimes install RUN curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash +RUN curl https://wasmtime.dev/install.sh -sSf | bash && echo 'export PATH=$PATH:/root/.wasmtime/bin' >> /root/.bash_profile # git settings RUN git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" && git config --global user.name "github-actions[bot]" WORKDIR ${ROOT_DIR} COPY ./ ./ +RUN chmod +x scripts/container-entry-point.sh +ENTRYPOINT [ "./scripts/container-entry-point.sh" ] diff --git a/build.sh b/scripts/build.sh similarity index 99% rename from build.sh rename to scripts/build.sh index f05c6e3..2905c2c 100755 --- a/build.sh +++ b/scripts/build.sh @@ -17,7 +17,7 @@ # /path/to/home/remill # /path/to/home/remill-build -ROOT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +ROOT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd ) REMILL_DIR=$( cd "$( realpath "${ROOT_DIR}/backend/remill" )" && pwd ) DOWNLOAD_DIR="$( cd "$( dirname "${REMILL_DIR}" )" && pwd )/lifting-bits-downloads" BUILD_DIR="${ROOT_DIR}/build" diff --git a/scripts/container-entry-point.sh b/scripts/container-entry-point.sh new file mode 100755 index 0000000..842faac --- /dev/null +++ b/scripts/container-entry-point.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# entry directory: /root/elfconv + +source ~/.bash_profile + +# build elfconv +./scripts/build.sh + +# elfconv integration test +cd build && ctest + +# bash +exec bash && source ~/.bash_profile diff --git a/dev.sh b/scripts/dev.sh similarity index 100% rename from dev.sh rename to scripts/dev.sh From ccce4de4de470515ee4985d9e7624b8ab19fa411 Mon Sep 17 00:00:00 2001 From: yomaytk Date: Mon, 15 Jan 2024 16:41:26 +0900 Subject: [PATCH 5/5] Add make command to container-entry-point.sh. --- scripts/container-entry-point.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/container-entry-point.sh b/scripts/container-entry-point.sh index 842faac..e1c47ab 100755 --- a/scripts/container-entry-point.sh +++ b/scripts/container-entry-point.sh @@ -7,7 +7,10 @@ source ~/.bash_profile ./scripts/build.sh # elfconv integration test -cd build && ctest +cd ~/elfconv/examples/print_hello && make +cd ~/elfconv/examples/eratosthenes_sieve && make +cd ~/elfconv/examples/hello && make +cd ~/elfconv/build && ctest # bash exec bash && source ~/.bash_profile