├── .gitignore ├── LICENSE ├── README.md └── riscv64-unknown-linux-gnu └── Dockerfile /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 KC Sivaramakrishnan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OCaml RISC-V cross compiler 2 | 3 | Dockerfiles for OCaml RISC-V cross compilation. 4 | 5 | Quick demo using pre-built image in Dockerhub. 6 | 7 | ```bash 8 | $ docker run -it kayceesrk/riscv64-ocaml:0.1.0 9 | root@933dfa3db228:~# echo 'let _ = print_endline "Hello,world!"' > hello.ml 10 | root@933dfa3db228:~# ocamlopt -ccopt -static hello.ml 11 | /riscv-ocaml/lib/ocaml/libasmrun.a(unix.o): In function `caml_dlopen': 12 | /riscv-ocaml-src/asmrun/unix.c:276: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 13 | root@933dfa3db228:~# file a.out 14 | a.out: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked, for GNU/Linux 3.0.0, with debug_info, not stripped 15 | root@933dfa3db228:~# spike /usr/local/riscv64-unknown-elf/bin/pk ./a.out 16 | Hello,world! 17 | root@933dfa3db228:~# 18 | ``` 19 | 20 | ## Acknowledgements 21 | 22 | The riscv backend for OCaml is from the 23 | [riscv-ocaml](https://github.com/nojb/riscv-ocaml) project. The 24 | dockerfiles in this repo extend the dockerfile from 25 | [riscv-tools-docker](https://github.com/anmolsahoo25/riscv-tools-docker), which 26 | is a part of the [Shakti Processor Program](https://shakti.org.in/) at IIT 27 | Madras. 28 | -------------------------------------------------------------------------------- /riscv64-unknown-linux-gnu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM iitmshakti/riscv-dev:0.5.0 as riscv-ocaml-cross 2 | RUN apt-get -y update 3 | RUN git clone https://github.com/kayceesrk/riscv-ocaml -b 4.07+cross riscv-ocaml-src 4 | WORKDIR riscv-ocaml-src 5 | RUN ./configure -no-ocamldoc -no-debugger -prefix /riscv-ocaml && \ 6 | make -j8 world.opt && make install 7 | ENV PATH="/riscv-ocaml/bin:${PATH}" 8 | RUN make clean && \ 9 | ./configure --target riscv64-unknown-linux-gnu -prefix /riscv-ocaml \ 10 | -no-ocamldoc -no-debugger -target-bindir /riscv-ocaml/bin && \ 11 | make -j4 world || /bin/true 12 | RUN make -j4 opt 13 | RUN cp /riscv-ocaml/bin/ocamlrun byterun 14 | RUN make install 15 | 16 | FROM iitmshakti/riscv-dev:0.5.0 17 | RUN apt-get -y update 18 | ENV PATH="${PATH}:/riscv-ocaml/bin" 19 | COPY --from=riscv-ocaml-cross /riscv-ocaml /riscv-ocaml 20 | 21 | ENTRYPOINT ["/bin/bash"] 22 | --------------------------------------------------------------------------------