Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Coverage

on:
push:
branches: [master]
pull_request:
branches: [master]

concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
OCAMLRUNPARAM: b

jobs:
coverage:
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Use Node.js
uses: actions/setup-node@v6
with:
cache: yarn
node-version-file: .nvmrc

- name: Install npm packages
run: yarn install

- name: Install system dependencies
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
packages: bubblewrap darcs g++-multilib gcc-multilib mercurial musl-tools rsync cmake
version: v4

- name: Determine Rust toolchain version
id: rust-version
run: |
version="$(awk -F '"' '/^rust-version[[:space:]]*=/ { print $2; exit }' rewatch/Cargo.toml)"
echo "version=${version}" >> "$GITHUB_OUTPUT"

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.rust-version.outputs.version }}
components: clippy, rustfmt

- name: Build rewatch
run: cargo build --manifest-path rewatch/Cargo.toml --release

- name: Copy rewatch binary
run: |
cp rewatch/target/release/rescript rescript
./scripts/copyExes.js --rewatch

- name: Use OCaml
uses: ocaml/setup-ocaml@v3.6.0
with:
ocaml-compiler: 5.3.0
opam-pin: false

- name: Install OPAM dependencies (incl. bisect_ppx)
run: opam install . --deps-only --with-test --with-dev-setup

- name: Run coverage
run: opam exec -- make coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: _coverage/coverage.json
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ _build_playground
node_modules
*.dump
coverage
_coverage/
bisect*.coverage

lib/ocaml
tests/build_tests/*/lib/
Expand Down
18 changes: 2 additions & 16 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
compiler/js_parser/**
compiler/ml/cmt_format.ml
compiler/core/js_name_of_module_id.ml
compiler/core/js_pass_debug.ml
compiler/core/lam_util.ml
compiler/core/lam_compile_main.ml
compiler/ext/bs_hash_stubs.ml
compiler/ext/js_reserved_map.ml
compiler/ext/ext_string.ml
compiler/ext/ext_string.mli
compiler/ext/ext_sys.ml
compiler/ext/hash.cppo.ml
compiler/ext/hash_set.cppo.ml
compiler/ext/map.cppo.ml
compiler/ext/ordered_hash_map.cppo.ml
compiler/ext/set.cppo.ml
compiler/ext/vec.cppo.ml
**/*.cppo.ml
**/*.cppo.mli
compiler/syntax/compiler-libs-406/*
83 changes: 82 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,87 @@ format: | $(YARN_INSTALL_STAMP)
checkformat: | $(YARN_INSTALL_STAMP)
./scripts/format_check.sh

# Coverage (bisect_ppx)
#
# Requires the `bisect_ppx` opam package (>= 2.8.0) in your switch:
# opam install bisect_ppx
# or pull it in via the rescript dev-setup deps:
# opam install . --deps-only --with-dev-setup
#
# Quick start:
# make coverage # run full test suite, generate report
# make clean-coverage # remove coverage artifacts
#
# Outputs (under _coverage/):
# html/index.html — human-browsable line-level report
# coverage.json — Coveralls-format JSON, queryable with jq:
# { source_files: [{ name, coverage: [null|N, ...] }] }
# null = not instrumented, 0 = uncovered, N > 0 = hit count
# e.g. uncovered line numbers in one file:
# jq -r --arg f compiler/ml/typecore.ml \
# '.source_files[] | select(.name==$f) | .coverage
# | to_entries[] | select(.value==0) | (.key+1)' \
# _coverage/coverage.json

COVERAGE_DIR := _coverage
COVERAGE_FILES_DIR := $(COVERAGE_DIR)/files
COVERAGE_HTML_DIR := $(COVERAGE_DIR)/html
COVERAGE_JSON := $(COVERAGE_DIR)/coverage.json
COVERAGE_BISECT_PREFIX := $(abspath $(COVERAGE_FILES_DIR))/bisect

# Re-builds the toolchain with bisect_ppx instrumentation and swaps the
# instrumented binaries into BIN_DIR so any test runner that shells out to
# `bsc` produces .coverage files.
.PHONY: coverage-build
coverage-build: | $(YARN_INSTALL_STAMP)
dune build --instrument-with bisect_ppx
@$(foreach bin,$(COMPILER_DUNE_BINS),touch $(bin);)
@$(foreach bin,$(COMPILER_BIN_NAMES), \
cp $(DUNE_BIN_DIR)/$(bin)$(PLATFORM_EXE_EXT) $(BIN_DIR)/$(bin).exe && \
chmod 755 $(BIN_DIR)/$(bin).exe;)

.PHONY: coverage-prepare
coverage-prepare: clean-coverage coverage-build
mkdir -p $(COVERAGE_FILES_DIR)

# Build the runtime with the instrumented bsc so subsequent test runs have
# a fresh stdlib. Coverage from the runtime build is discarded so reports
# only reflect what the tests exercised.
.PHONY: coverage-lib
coverage-lib: coverage-prepare
BISECT_FILE=$(COVERAGE_BISECT_PREFIX)-discard BISECT_SILENT=YES \
yarn workspace @rescript/runtime build
rm -f $(COVERAGE_BISECT_PREFIX)-discard*.coverage

.PHONY: coverage-run
coverage-run: coverage-lib
BISECT_FILE=$(COVERAGE_BISECT_PREFIX) BISECT_SILENT=YES \
node scripts/test.js -all

.PHONY: coverage-report
coverage-report:
bisect-ppx-report html \
--coverage-path $(COVERAGE_FILES_DIR) \
--ignore-missing-files \
-o $(COVERAGE_HTML_DIR)
bisect-ppx-report coveralls \
--coverage-path $(COVERAGE_FILES_DIR) \
--ignore-missing-files \
$(COVERAGE_JSON)
bisect-ppx-report summary \
--coverage-path $(COVERAGE_FILES_DIR)
@echo ""
@echo "HTML report: $(COVERAGE_HTML_DIR)/index.html"
@echo "JSON data: $(COVERAGE_JSON)"

.PHONY: coverage
coverage: coverage-run coverage-report

.PHONY: clean-coverage
clean-coverage:
rm -rf $(COVERAGE_DIR)
find . -name 'bisect*.coverage' -not -path './_build/*' -delete

# Clean

clean-gentype:
Expand All @@ -225,7 +306,7 @@ clean-gentype:

clean-tests: clean-gentype

clean: clean-lib clean-compiler clean-rewatch
clean: clean-lib clean-compiler clean-rewatch clean-coverage

dev-container:
docker build -t rescript-dev-container docker
Expand Down
2 changes: 2 additions & 0 deletions analysis/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
(package analysis)
(modes byte exe)
(name main)
(instrumentation
(backend bisect_ppx))
(libraries analysis))
2 changes: 2 additions & 0 deletions analysis/src/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(library
(name analysis)
(instrumentation
(backend bisect_ppx))
(flags
(-w "+6+26+27+32+33+39"))
(libraries unix str ext ml jsonlib syntax reanalyze))
20 changes: 20 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
coverage:
status:
project:
default:
informational: true
threshold: 0.5%
patch:
default:
informational: true
threshold: 0.5%

comment:
layout: "diff, files"
require_changes: true
require_base: false
require_head: true
behavior: default

github_checks:
annotations: false
2 changes: 2 additions & 0 deletions compiler/bsc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
(name rescript_compiler_main)
(public_name bsc)
(package rescript)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-30-40-41-42-48-70))
(libraries common core depends flow_parser gentype syntax))
5 changes: 2 additions & 3 deletions compiler/common/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(library
(name common)
(wrapped false)
(preprocess
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-9-40-42))
(libraries syntax))
29 changes: 26 additions & 3 deletions compiler/core/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
(library
(name core)
(wrapped false)
(preprocess
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
Comment on lines -4 to -6
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dune was unabled to have both this preprocess stanza and the ppx stanza. There were such few files actually using cppo flags that I just converted them into per file rules.

(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-27-30-40-41-42-48-70))
(libraries depends ext flow_parser frontend gentype))

(rule
(target js_name_of_module_id.ml)
(deps js_name_of_module_id.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target js_pass_debug.ml)
(deps js_pass_debug.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target lam_compile_main.ml)
(deps lam_compile_main.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target lam_util.ml)
(deps lam_util.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions compiler/depends/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name depends)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-40-42))
(libraries common))
File renamed without changes.
47 changes: 39 additions & 8 deletions compiler/ext/dune
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
(library
(name ext)
(wrapped false)
(preprocess
(action
(run
%{bin:cppo}
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{input-file})))
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-42-40-9-48-70))
(foreign_stubs
(language c)
(names ext_basic_hash_stubs)))

(rule
(target bs_hash_stubs.ml)
(deps bs_hash_stubs.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target js_reserved_map.ml)
(deps js_reserved_map.cppo.ml)
(action
(run
%{bin:cppo}
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{deps}
-o
%{target})))

(rule
(target ext_sys.ml)
(deps ext_sys.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target ext_string.ml)
(deps ext_string.cppo.ml)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(target ext_string.mli)
(deps ext_string.cppo.mli)
(action
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(targets hash_set_string.ml)
(deps hash_set.cppo.ml)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions compiler/frontend/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name frontend)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-40-42-70))
(libraries common ml))
2 changes: 2 additions & 0 deletions compiler/gentype/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name gentype)
(wrapped false)
(instrumentation
(backend bisect_ppx))
(flags
(:standard -w +a-4-9-40-41-42-48-70))
(libraries ml))
File renamed without changes.
Loading
Loading