Skip to content

Commit

Permalink
Merge pull request #246 from mtzguido/stage
Browse files Browse the repository at this point in the history
Staged build
  • Loading branch information
mtzguido authored Dec 28, 2024
2 parents d5c8c0a + 4d60ca4 commit 99ae9f5
Show file tree
Hide file tree
Showing 504 changed files with 1,774 additions and 114,418 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
- name: Build Pulse and its dependencies
run: |
ci_docker_image_tag=pulse:local-binary-run-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT
docker buildx build --secret id=DZOMO_GITHUB_TOKEN -t $ci_docker_image_tag -f src/ci/package.Dockerfile --build-arg FSTAR_BRANCH=$FSTAR_BRANCH --build-arg CI_BRANCH=$GITHUB_REF_NAME --build-arg opamthreads=$(nproc) .
docker run $ci_docker_image_tag /bin/bash -c 'cat $PULSE_HOME/src/ci/pulse.tar.gz || true' > pulse.tar.gz
docker buildx build --secret id=DZOMO_GITHUB_TOKEN -t $ci_docker_image_tag -f ci/package.Dockerfile --build-arg FSTAR_BRANCH=$FSTAR_BRANCH --build-arg CI_BRANCH=$GITHUB_REF_NAME --build-arg opamthreads=$(nproc) .
docker run $ci_docker_image_tag /bin/bash -c 'cat $PULSE_HOME/ci/pulse.tar.gz || true' > pulse.tar.gz
gunzip pulse.tar.gz
env:
DZOMO_GITHUB_TOKEN: ${{ secrets.DZOMO_GITHUB_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linux-x64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
uses: actions/checkout@v2
- name: Identify the base FStar branch and the notification channel
run: |
echo "FSTAR_BRANCH=$(jq -c -r '.RepoVersions.fstar' src/ci/config.json || echo master)" >> $GITHUB_ENV
echo "CI_SLACK_CHANNEL=$(jq -c -r '.NotificationChannel' src/ci/config.json)" >> $GITHUB_ENV
echo "FSTAR_BRANCH=$(jq -c -r '.RepoVersions.fstar' ci/config.json || echo master)" >> $GITHUB_ENV
echo "CI_SLACK_CHANNEL=$(jq -c -r '.NotificationChannel' ci/config.json)" >> $GITHUB_ENV
- name: Determine the build flavor
run: |
if docker image inspect fstar:local-branch-$FSTAR_BRANCH ; then echo CI_FLAVOR=hierarchic >> $GITHUB_ENV ; else echo CI_FLAVOR=ci >> $GITHUB_ENV ; fi
- name: Build Pulse and its dependencies
run: |
ci_docker_image_tag=pulse:local-run-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT
docker build -t $ci_docker_image_tag -f src/ci/$CI_FLAVOR.Dockerfile --build-arg FSTAR_BRANCH=$FSTAR_BRANCH --build-arg opamthreads=$(nproc) . |& tee BUILDLOG
docker build -t $ci_docker_image_tag -f ci/$CI_FLAVOR.Dockerfile --build-arg FSTAR_BRANCH=$FSTAR_BRANCH --build-arg opamthreads=$(nproc) . |& tee BUILDLOG
if ! { echo $GITHUB_REF_NAME | grep '/' ; } ; then
docker tag $ci_docker_image_tag pulse:local-branch-$GITHUB_REF_NAME
fi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
- name: Package Pulse
run: |
source pulse/.github/env.sh
pulse/src/ci/package.sh -j
pulse/ci/package.sh -j
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: pulse-Darwin_x86_64.tar.gz
path: pulse/src/ci/pulse.tar.gz
path: pulse/ci/pulse.tar.gz
4 changes: 2 additions & 2 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
- name: Build a package
shell: C:\cygwin64\bin\bash.exe --login '{0}'
run: |
$GITHUB_WORKSPACE/src/ci/package.sh -j 8 && echo "There is a CR at the end of this line"
$GITHUB_WORKSPACE/ci/package.sh -j 8 && echo "There is a CR at the end of this line"
- name: Archive the package
uses: actions/upload-artifact@v3
with:
name: pulse-Windows_x86_64.zip
path: src\ci\pulse.zip
path: ci\pulse.zip
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ LICENSE-z3.txt

# Created by CI
BUILDLOG

out
_output
_cache
66 changes: 31 additions & 35 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ In all cases (user or developer), please first read `README.md`
PulseC. This F* code typechecks against the F* sources.
* In `src/syntax-extension`: A top-level parser hook for the custom
syntax of pulse. This F* code typechecks against the F* sources.
* In `src/ocaml/plugin/generated`: A snapshot of the generated OCaml
code for the Pulse plugin, containing the extracted implementations
of the Pulse checker and the Pulse and PulseC extraction rules to
krml.
* In `src/ml`: Base OCaml files for the checker.

## Modifying the user-facing Pulse libraries

Expand All @@ -29,20 +26,17 @@ the Pulse root directory.

Dependency diagram:

* `lib/pulse` and `lib/pulse/core` can be typechecked without loading
* `lib/common` and `lib/core` can can be typechecked without loading
the Pulse plugin
* `lib/pulse/lib` and its subdirectories depend on `lib/pulse`,
`lib/pulse/core`, and need to load the Pulse plugin
* `lib/pulse/c` depends on `lib/pulse/lib`
* `lib/pulse` and its subdirectories depend on `lib/common`,
and required the Pulse plugin
* `lib/core` and `lib/pulse` are independent as far as checking goes.
The former is the formalization of the Pulse separation logic,
culminating in providing the interface `Pulse.Lib.Core.fsti` in
`lib/common`. The latter are user-facing Pulse modules.

## Modifying the Pulse checker

If you modify the Pulse checker in `src/checker`, you need to
regenerate and recompile the corresponding OCaml snapshot, with `make -j
boot-checker` from the Pulse root directory.

Modifying the Pulse checker does not require a source repository clone
of F*.
The top-level Makefile knows about these dependencies and will parallelize
the checking.

### Notes on the implementation of Pulse

Expand Down Expand Up @@ -144,22 +138,24 @@ generated OCaml files beforehand.

## Testing

`share/pulse` contains all examples and tests. You can run `make -j -C
share/pulse` to verify and test them. This rule will work whether you have
Karamel or not. If you have Karamel with the `KRML_HOME` variable set, then
this rule will also extract and compile (and sometimes run) C extraction
examples. Alternatively, you can run `make -j test` from the Pulse root
directory, which will build Pulse beforehand.

If you have Docker, you can run `docker build -f
src/ci/opam.Dockerfile .` to test the opam installation of Pulse
(including all dependencies.) This will also verify all examples and
tests, by moving them outside of the Pulse directory hierarchy
beforehand, to make sure that the location of those examples does not
need to depend on the location of Pulse.

Finally, you can run `make -j -C src ci` to re-extract, recompile and
re-test everything. This rule also checks that the re-extracted
snapshot is no newer than the current snapshot. If you have Docker,
you can run the `ci` rule with `docker build -f src/ci/ci.Dockerfile
.` which will also install all dependencies automatically.
There are simple tests in `test/` and examples in `share/pulse`.
Anything that is not user-facing (like simple regression tests) should
go into `test/`. All of `share/pulse` is distributed in the package.

You can run `make -j test` to verify and test them. This rule will
work whether you have Karamel or not. If you have Karamel with the
`KRML_HOME` variable set, then this rule will also extract and compile
(and sometimes run) C extraction examples. Alternatively, you can run
`make -j test` from the Pulse root directory, which will build Pulse
beforehand.

If you have Docker, you can run `docker build -f ci/opam.Dockerfile .`
to test the opam installation of Pulse (including all dependencies.)
This will also verify all examples and tests, by moving them outside of
the Pulse directory hierarchy beforehand, to make sure that the location
of those examples does not need to depend on the location of Pulse.

Finally, you can run `make -j ci` to re-extract, recompile and re-test
everything. If you have Docker, you can run the `ci` rule with `docker
build -f ci/ci.Dockerfile .` which will also install all dependencies
automatically.
172 changes: 113 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,76 +1,130 @@
include mk/common.mk
include mk/locate.mk

# Pulse's `Makefile`s rely on recent GNU Make's "shortest stem" rule,
# so we need to rule out older `make`s.

# GM: ifeq? That sounds oddly specific?
# Also is this still true?
ifeq (3.81,$(MAKE_VERSION))
$(error You seem to be using the OSX antiquated Make version. Hint: brew \
install make, then invoke gmake instead of make)
endif

all: build

# Define the Pulse root directory. We need to fix it to use the Windows path convention on Windows+Cygwin.
ifeq ($(OS),Windows_NT)
PULSE_HOME := $(shell cygpath -m $(CURDIR))
else
PULSE_HOME := $(CURDIR)
endif

include $(PULSE_HOME)/share/pulse/Makefile.locate-fstar

.PHONY: build
build:
+$(MAKE) -C src build-ocaml
+$(MAKE) -C lib/pulse

# NOTE: this default goal will not build pulse2rust. We do check
# PulseCore implementation files (lib/core) by choice, but that could be
# omitted. Use `make all` to build all of this plus pulse2rust.
.DEFAULT_GOAL := default

.PHONY: default
default: local-install lib-core

.PHONY: all
all: local-install # build plugin and library, and install in out/
all: lib-core # also check implentation files in core
all: pulse2rust # and pulse2rust tool

.PHONY: .force
.force:

## Checking and extracting the plugin
checker.src: .force
$(MAKE) -f mk/checker.mk

extraction.src: .force
$(MAKE) -f mk/extraction.mk

syntax_extension.src: .force
$(MAKE) -f mk/syntax_extension.mk

plugin.src: checker.src extraction.src syntax_extension.src

## Building the plugin with dune
plugin.build: plugin.src .force
$(FSTAR_EXE) --ocamlenv \
dune build --root=build/ocaml

## Installing the plugin into out/
plugin: plugin.build .force
$(FSTAR_EXE) --ocamlenv \
dune install --root=build/ocaml --prefix=$(abspath build/ocaml/installed)

# Checking the library. Modules in common are shared between core and pulse, but core
# and pulse are independent otherwise.
lib-common: .force
$(MAKE) -f mk/lib-common.mk

lib-core: lib-common .force
$(MAKE) -f mk/lib-core.mk

lib-pulse: plugin lib-common .force
$(MAKE) -f mk/lib-pulse.mk

local-install: override PREFIX=$(CURDIR)/out
local-install: do-install

.PHONY: do-install
do-install: plugin lib-pulse
rm -rf $(PREFIX)/lib/pulse
rm -rf $(PREFIX)/share/pulse
mkdir -p $(PREFIX)/lib/pulse
mkdir -p $(PREFIX)/lib/pulse/lib
mkdir -p $(PREFIX)/share/pulse
# Install plugin.
$(FSTAR_EXE) --ocamlenv \
dune install --root=build/ocaml --prefix=$(abspath $(PREFIX))
# Install library (cp -u: don't copy unless newer, -p: preserve time/perms)
# We install it flat. Note that lib/core is not included, but still some PulseCore
# checked files make it in. We could add:
# \( -not -name 'PulseCore.*' \)
# to the condition but we do need PulseCore.FractionalPermission and others,
# so I'm keeping this for now (it's already the case) and will do a PR later
# to change their namespace.
find lib/pulse lib/common \
\( -name '*.fst' -o -name '*.fsti' -o -name '*.checked' -o -name '*.ml' \) -and \
-exec cp -p -u -t $(PREFIX)/lib/pulse/lib {} \;
# Set up fstar.include so users only include lib/pulse
echo 'lib' > $(PREFIX)/lib/pulse/fstar.include

# Install share/ too, as-is.
cp -p -t $(PREFIX) -r share/

.PHONY: clean
clean:
+$(MAKE) -C lib/pulse clean ; true

.PHONY: test
test: all
$(MAKE) -f mk/checker.mk clean
$(MAKE) -f mk/extraction.mk clean
$(MAKE) -f mk/syntax_extension.mk clean
$(MAKE) -f mk/lib-pulse.mk clean
$(MAKE) -f mk/lib-core.mk clean
$(MAKE) -f mk/lib-common.mk clean

.PHONY: test-pulse
test-pulse: local-install
+$(MAKE) -C test

.PHONY: test-share
test-share: local-install
+$(MAKE) -C share/pulse

ifeq (,$(PREFIX))
PREFIX := /usr/local
endif
ifeq ($(OS),Windows_NT)
PREFIX := $(shell cygpath -m $(PREFIX))
endif
export PREFIX

INSTALL := $(shell ginstall --version 2>/dev/null | cut -c -8 | head -n 1)
ifdef INSTALL
INSTALL := ginstall
else
INSTALL := install
endif
export INSTALL

.PHONY: install install-lib install-share

install-lib:
+$(MAKE) -C lib/pulse install
.PHONY: test-pulse2rust
test-pulse2rust: test-share # test-pulse2rust uses .checked files from share/
+$(MAKE) -C pulse2rust
+$(MAKE) -C pulse2rust test

install-share:
+$(MAKE) -C share/pulse install
.PHONY: test
test: test-pulse test-share test-pulse2rust test-qs

install: install-lib install-share
.PHONY: test-qs
test-qs: local-install
$(MAKE) -C qs test

.PHONY: pulse2rust
pulse2rust:
pulse2rust: lib-pulse plugin
+$(MAKE) -C pulse2rust

.PHONY: boot
boot:
+$(MAKE) -C src boot

.PHONY: boot-checker
boot-checker:
+$(MAKE) -C src boot-checker

.PHONY: full-boot
full-boot:
+$(MAKE) -C src full-boot

# Make can figure out internal dependencies between all and test.
.PHONY: ci
ci:
+$(MAKE) -C src ci
ci: all test

.PHONY: install
install: PREFIX ?= /usr/local
install: do-install
6 changes: 1 addition & 5 deletions Pulse.fst.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
"--z3version", "4.13.3"
],
"include_dirs": [
"lib/pulse",
"lib/pulse/core",
"lib/pulse/lib",
"lib/pulse/lib/pledge",
"lib/pulse/lib/class",
"lib",
"share/pulse/examples",
"share/pulse/examples/bug-reports",
"share/pulse/examples/by-example",
Expand Down
Loading

0 comments on commit 99ae9f5

Please sign in to comment.