Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements #179

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!corrode.cabal
!LICENSE
!Main.lhs
!Main.md
!Setup.hs
!src/
27 changes: 26 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
# Sudo used for custom apt setup
sudo: true

cache:
directories:
- $HOME/.ghc
- $HOME/.cabal
- $HOME/.stack

# Add new environments to the build here:
env:
- GHCVER=7.10.1 CABALVER=1.22
- GHCVER=8.0.1 CABALVER=1.22
- GHCVER=head CABALVER=head

# Allow for develop branch to break
matrix:
include:
- env: GHCVER=8.0.2
before_install:
- mkdir -p ~/.local/bin
- export PATH=$HOME/.local/bin:$PATH
- travis_retry curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
install:
- echo $PATH
- stack build
script:
- stack test
- env:
before_install: true
install: true
script: make docker
- env:
before_install: true
install: true
script: make docs-on-docker
# Allow for develop branch to break
allow_failures:
- env: GHCVER=head CABALVER=head

Expand Down
24 changes: 19 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
FROM ubuntu:16.04
RUN apt-get update && apt-get install git ghc haskell-stack -y
RUN git clone https://github.com/jameysharp/corrode.git
RUN cd corrode && stack build && stack install
ENV PATH="/root/.local/bin:${PATH}"
ARG GHCVER=8.0.2
FROM haskell:${GHCVER} AS builder
ARG HAPPYVER=1.19.5
ARG ALEXVER=3.2.1
RUN useradd --user-group --create-home --home-dir /home/builder builder
USER builder:builder
RUN cabal update && cabal install happy-${HAPPYVER} alex-${ALEXVER}
RUN mkdir /home/builder/build
COPY ./corrode.cabal /home/builder/build/
RUN cd /home/builder/build && cabal install --only-dependencies -j4
COPY . /home/builder/build/
RUN cd /home/builder/build && cabal install

FROM debian:buster-slim
RUN useradd --user-group corrode
USER corrode:corrode
COPY --from=builder /home/builder/.cabal/bin/corrode /opt/corrode/bin/corrode
ENTRYPOINT ["/opt/corrode/bin/corrode"]
CMD ["--help"]
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
.PHONY: docs
docs: doc/corrode.pdf doc/cfg.pdf doc/driver.pdf

PANDOC = pandoc

doc/corrode.pdf: src/Language/Rust/Corrode/C.md
pandoc --from markdown --to latex --variable papersize=letter --variable geometry=margin=1in --output "$@" "$^"
$(PANDOC) --from markdown --to latex --variable papersize=letter --variable geometry=margin=1in --output "$@" "$^"

doc/cfg.pdf: src/Language/Rust/Corrode/CFG.md
pandoc --from markdown --to latex --variable papersize=letter --variable geometry=margin=1in --output "$@" "$^"
$(PANDOC) --from markdown --to latex --variable papersize=letter --variable geometry=margin=1in --output "$@" "$^"

doc/driver.pdf: Main.md
pandoc --from markdown --to latex --variable papersize=letter --variable geometry=margin=1in --output "$@" "$^"
$(PANDOC) --from markdown --to latex --variable papersize=letter --variable geometry=margin=1in --output "$@" "$^"

.PHONY: corrode-docs-builder
corrode-docs-builder:
docker build -t $@ doc

.PHONY: docs-on-docker
docs-on-docker: corrode-docs-builder
$(MAKE) docs PANDOC="docker run --rm -v \"$(CURDIR)\":/tmp/build -w /tmp/build $^"

.PHONY: docker
docker:
ifdef BUILD_GHCVER
docker build --build-arg GHCVER=$${BUILD_GHCVER:?} --build-arg HAPPYVER=$${BUILD_HAPPYVER:?} --build-arg ALEXVER=$${BUILD_ALEXVER:?} .
else
docker build .
endif
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ navigating to the `corrode` directory, installing the `happy` and `alex` tools,
and then building and installing the `corrode` package:

```
cabal update
cabal install happy
cabal install alex
cabal install
Expand Down Expand Up @@ -109,8 +110,8 @@ replace the original C, not just as an intermediate step in a compiler
toolchain.

Corrode aims to produce Rust source code which behaves exactly the same
way that the original C source behaved, if the input is free of
undefined and implementation-defined behavior. In the presence of
way that the original C source behaved (if the input is free of
undefined and implementation-defined behavior). In the presence of
undefined behavior, we've tried to pick a behavior that isn't too
surprising. For example, if a signed addition might overflow (which is
undefined behavior in C), Corrode just translates it to Rust's `+`
Expand All @@ -119,7 +120,7 @@ operator, which panics on overflow in debug builds.
The compiled Rust source in turn will be ABI-compatible with the
original C. If you compile Corrode-generated Rust to a `.o` file, you
can link to it exactly as if it were generated from the original C.
Every function that Corrode generates with be annotated with the `extern
Every function that Corrode generates will be annotated with the `extern
"C"` modifier.

At the same time, Corrode should produce code which is recognizably
Expand Down
1 change: 1 addition & 0 deletions doc/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
7 changes: 7 additions & 0 deletions doc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM debian:buster-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
pandoc \
texlive \
lmodern \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["pandoc"]