-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gcc-riscv-docker: use Makefiles and restructure folder
- Loading branch information
1 parent
77b24ba
commit ce9deee
Showing
7 changed files
with
151 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Author: Nic Cantieni | ||
# Date: 18.08.2022 | ||
|
||
|
||
NAME = gcc-riscv-docker | ||
VERSION = latest | ||
|
||
BUILDER = podman | ||
|
||
DOCKERFILE = Dockerfile | ||
|
||
BUILD = $(BUILDER) build . --tag $(NAME):$(VERSION) --file $(DOCKERFILE) | ||
|
||
.PHONY: build | ||
build : | ||
$(BUILD) | ||
|
||
.PHONY: nocache | ||
nocache : | ||
$(BUILD) --no-cache | ||
|
||
.PHONY: save | ||
save : | ||
$(BUILDER) image save -o $(NAME).tar $(NAME):$(VERSION) | ||
|
||
.PHONY: clean | ||
clean : | ||
rm $(NAME).tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,47 @@ | ||
# `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. | ||
This repository contains a toolchain for building and running containers (i.e. with Docker or Podman) in order to compile and run RISC-V 64 in the container. | ||
|
||
## 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. | ||
### Building the container | ||
The whole thing is built with `make`. | ||
|
||
If you want to use Docker instead of Podman, adjust `BUILDER` in the `Makefile`. | ||
|
||
```bash | ||
# make scripts executable | ||
chmod u+x build.sh | ||
chmod u+x compile.sh | ||
# build the image | ||
make build | ||
|
||
# build the container | ||
./build.sh | ||
# build the image without using cached results | ||
make nocache | ||
|
||
# compile the file | ||
./compile.sh main.c -o main.o | ||
# export the image to gcc-riscv-docker.tar | ||
make save | ||
|
||
# delete the .tar | ||
make clean | ||
``` | ||
|
||
### Using the container | ||
|
||
An exemplary usage is in `./example`, and there is a separate `Makefile`. | ||
|
||
If you want to use Docker instead of Podman, adjust `RUNNER` in the `Makefile`. | ||
|
||
To adjust which files are built, change `COMPILE_FILES` and `COMPILE_OUT` in the `Makefile` accordingly. | ||
|
||
```bash | ||
cd example | ||
|
||
# compile main.c to main.o | ||
make compile | ||
|
||
# run main.o with spike and a proxy-kernel (pk) | ||
make run | ||
|
||
# just start a container and connect a shell (for inspection etc.) | ||
# ATTN: The container is deleted, only the contents of the outside | ||
# local directory will be kept | ||
make login | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 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 and invoces riscv64-linux-gnu-gcc with COMPILER_FLAGS | ||
|
||
NAME = gcc-riscv-docker | ||
RUNNER = podman | ||
|
||
CONTAINER = gcc-riscv-docker | ||
CONTAINER_VERSION = latest | ||
CONTAINER_IDENT = $(CONTAINER):$(CONTAINER_VERSION) | ||
|
||
VOLUME_LOCAL = $$PWD | ||
VOLUME_CONTAINER = /builddir | ||
|
||
CONTAINER_FLAGS = --rm --name $(NAME) \ | ||
--volume $(VOLUME_LOCAL):$(VOLUME_CONTAINER) \ | ||
--workdir $(VOLUME_CONTAINER) \ | ||
|
||
# COMPILE # | ||
|
||
COMPILE_FILES = main.c | ||
COMPILE_OUT = main.o | ||
|
||
COMPILER = riscv64-unknown-elf-gcc | ||
|
||
COMPILE_CONTAINER_FLAGS = $(CONTAINER_FLAGS) \ | ||
--entrypoint $(COMPILER) \ | ||
|
||
COMPILER_FLAGS = -c -O3 -Wno-int-conversion -Wall \ | ||
-march=rv64ima -mabi=lp64 | ||
|
||
COMPILE = $(RUNNER) run $(COMPILE_CONTAINER_FLAGS) $(CONTAINER_IDENT) $(COMPILER_FLAGS) $(COMPILE_FILES) -o $(COMPILE_OUT) | ||
|
||
# RUN WITH SPIKE # | ||
|
||
SPIKE = spike | ||
PK = /usr/local/riscv64-linux-gnu/bin/pk | ||
|
||
RUN_CONTAINER_FLAGS = $(CONTAINER_FLAGS) \ | ||
--entrypoint $(SPIKE) \ | ||
|
||
RUNNER_FLAGS = -d $(PK) | ||
|
||
RUN = $(RUNNER) run $(RUN_CONTAINER_FLAGS) $(CONTAINER_IDENT) $(RUNNER_FLAGS) $(COMPILE_OUT) | ||
|
||
# LOGIN TO CONTAINER # | ||
|
||
LOGIN_CONTAINER_FLAGS = $(CONTAINER_FLAGS) -it | ||
|
||
LOGIN = $(RUNNER) run $(LOGIN_CONTAINER_FLAGS) $(CONTAINER_IDENT) | ||
|
||
.PHONY: compile | ||
compile : | ||
$(COMPILE) | ||
|
||
.PHONY: run | ||
run : | ||
$(RUN) | ||
|
||
.PHONY: login | ||
login : | ||
$(LOGIN) |
File renamed without changes.