Skip to content

Commit

Permalink
gcc-riscv-docker: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
niccantieni committed Aug 18, 2022
0 parents commit 77b24ba
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.DS_Store

*.code-workspace

*.ignore

*.local

*.log

*.o
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ubuntu:latest

RUN apt update -y
RUN apt upgrade -y
RUN apt install -y build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `gcc-riscv-docker`: a container image for compiling RISC-V 64

This repository contains a `Dockerfile` which builds a container image based on `ubuntu:latest` and installs the gcc-crosscompiler for RISC-V 64.

## Usage

The script is built with `podman` in mind, but should work just as well with `Docker`. To change this, adjust the comments in the files.


```bash
# make scripts executable
chmod u+x build.sh
chmod u+x compile.sh

# build the container
./build.sh

# compile the file
./compile.sh main.c -o main.o
```
11 changes: 11 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/zsh
# Author: Nic Cantieni
# Date: 18.08.2022

# Builds a container image from the Dockerfile.

# podman
podman build -t gcc-riscv-docker:latest .

# docker
# docker build -t gcc-riscv-docker:latest .
9 changes: 9 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/zsh
# Author: Nic Cantieni
# Date: 18.08.2022

# Runs a temporary (--rm) container of the image gccriscv:latest, and mounts the current working directory into /builddir in the container, sets that as the working directory, invoces riscv64-linux-gnu-gcc and passes all arguments to this script through to riscv64-linux-gnu-gcc.

podman run --rm --entrypoint riscv64-linux-gnu-gcc --volume $PWD:/builddir --workdir /builddir --name gcc-riscv-docker gcc-riscv-docker:latest "$@"

# docker run --rm --entrypoint riscv64-linux-gnu-gcc --volume $PWD:/builddir --workdir /builddir --name gcc-riscv-docker gcc-riscv-docker:latest "$@"
20 changes: 20 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#define ERROR 1
#define INPUT 70

int check (int number) {

if (number % 2) {
return -ERROR;
} else {
return 42;
}
}

int main () {

if (check(INPUT) < 0) {
return 1;
} else {
return 0;
}
}

0 comments on commit 77b24ba

Please sign in to comment.