Skip to content
Merged
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
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,30 @@ $(YARN_INSTALL_STAMP): $(YARN_INSTALL_SOURCES)
# Compiler

COMPILER_SOURCE_DIRS := compiler syntax tests analysis tools build_system
COMPILER_SOURCES = $(shell find $(COMPILER_SOURCE_DIRS) -type f \( -name '*.ml' -o -name '*.mli' -o -name '*.c' -o -name '*.h' -o -name '*.dune' -o -name dune -o -name dune-project \))
# Besides the sources, the dune files outside those directories: the root ones
# and the rules in packages/dune that copy the binaries into the packages.
COMPILER_SOURCES = $(shell find $(COMPILER_SOURCE_DIRS) -type f \( -name '*.ml' -o -name '*.mli' -o -name '*.c' -o -name '*.h' -o -name '*.dune' -o -name dune -o -name dune-project \)) dune dune-project packages/dune
COMPILER_BIN_NAMES := bsc rescript-editor-analysis rescript-tools rescript
COMPILER_EXES := $(addsuffix .exe,$(addprefix $(BIN_DIR)/,$(COMPILER_BIN_NAMES)))
RESCRIPT_EXE := $(BIN_DIR)/rescript.exe

compiler: $(COMPILER_EXES)

# The compiler binaries in $(BIN_DIR) are produced by dune itself: the
# promotion rules in compiler/sync/dune copy (and strip) them into the
# promotion rules in packages/dune copy (and strip) them into the
# platform npm package on every `dune build`, comparing content so unchanged
# binaries are not rewritten. Make only needs to know that running dune
# produces them.
$(COMPILER_BUILD_STAMP): $(COMPILER_SOURCES)
dune build

$(COMPILER_EXES): $(COMPILER_BUILD_STAMP)
@cmp -s $@ _build/default/compiler/sync/$(@F) || { \
rm -f _build/default/compiler/sync/$(@F); dune build; }
@cmp -s $@ _build/default/compiler/sync/$(@F) || { \
@cmp -s $@ _build/default/packages/$(@F) || { \
rm -f _build/default/packages/$(@F); dune build; }
@cmp -s $@ _build/default/packages/$(@F) || { \
echo "Error: $@ is missing or does not match the dune build output."; \
echo "Dune promotion did not produce it; check that this platform is"; \
echo "covered by a rule in compiler/sync/dune."; \
echo "covered by a rule in packages/dune."; \
exit 1; }
@test -x $@ || chmod 755 $@

Expand Down
1 change: 1 addition & 0 deletions changes/packaging-rules-location.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Move the rules that copy the executables into the platform packages from `compiler/sync/dune` to `packages/dune`.
1 change: 0 additions & 1 deletion compiler/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
frontend
gentype
playground
sync
syntax_cli
typing
version)
Expand Down
120 changes: 0 additions & 120 deletions compiler/sync/dune

This file was deleted.

2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(dirs compiler syntax tests analysis tools build_system)
(dirs compiler syntax tests analysis tools build_system packages)

; All warnings are enabled, except:
; - 4 (fragile-match): wildcard cases are used deliberately.
Expand Down
123 changes: 123 additions & 0 deletions packages/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
; Keep the npm platform packages' binaries in sync with every `dune build`.
;
; The @rescript/<platform>/bin copies are what cli/*.js, the test harnesses,
; and the runtime build actually run; these promotion rules are their only
; producer. Promotion compares content, so unchanged binaries are not
; rewritten and no-op builds cause no timestamp churn downstream.
;
; One rule per platform; %{system}/%{architecture} come from `ocamlc -config`
; (note: x64 is "amd64" there). Every package receives the build system as
; rescript.exe. The browser profile is excluded because it builds a
; playground-flavoured compiler that must never overwrite the native binaries.

; The packages themselves hold no dune sources.

(dirs)

(rule
Comment thread
cknitt marked this conversation as resolved.
Resolved
(enabled_if
(and
(<> %{profile} browser)
(= %{system} macosx)
(= %{architecture} arm64)))
(targets
bsc.exe
rescript-editor-analysis.exe
rescript-tools.exe
rescript.exe)
(deps
../compiler/bsc/rescript_compiler_main.exe
../analysis/bin/main.exe
../tools/bin/main.exe
../build_system/rescript.exe)
(mode
(promote
(until-clean)
(into @rescript/darwin-arm64/bin)))
(action
(progn
(run strip -o bsc.exe ../compiler/bsc/rescript_compiler_main.exe)
(run strip -o rescript-editor-analysis.exe ../analysis/bin/main.exe)
(run strip -o rescript-tools.exe ../tools/bin/main.exe)
(run strip -o rescript.exe ../build_system/rescript.exe))))

(rule
(enabled_if
(and
(<> %{profile} browser)
(= %{system} linux)
(= %{architecture} arm64)))
(targets
bsc.exe
rescript-editor-analysis.exe
rescript-tools.exe
rescript.exe)
(deps
../compiler/bsc/rescript_compiler_main.exe
../analysis/bin/main.exe
../tools/bin/main.exe
../build_system/rescript.exe)
(mode
(promote
(until-clean)
(into @rescript/linux-arm64/bin)))
(action
(progn
(run strip -o bsc.exe ../compiler/bsc/rescript_compiler_main.exe)
(run strip -o rescript-editor-analysis.exe ../analysis/bin/main.exe)
(run strip -o rescript-tools.exe ../tools/bin/main.exe)
(run strip -o rescript.exe ../build_system/rescript.exe))))

(rule
(enabled_if
(and
(<> %{profile} browser)
(= %{system} linux)
(= %{architecture} amd64)))
(targets
bsc.exe
rescript-editor-analysis.exe
rescript-tools.exe
rescript.exe)
(deps
../compiler/bsc/rescript_compiler_main.exe
../analysis/bin/main.exe
../tools/bin/main.exe
../build_system/rescript.exe)
(mode
(promote
(until-clean)
(into @rescript/linux-x64/bin)))
(action
(progn
(run strip -o bsc.exe ../compiler/bsc/rescript_compiler_main.exe)
(run strip -o rescript-editor-analysis.exe ../analysis/bin/main.exe)
(run strip -o rescript-tools.exe ../tools/bin/main.exe)
(run strip -o rescript.exe ../build_system/rescript.exe))))

(rule
(enabled_if
(and
(<> %{profile} browser)
(= %{system} mingw64)
(= %{architecture} amd64)))
(targets
bsc.exe
rescript-editor-analysis.exe
rescript-tools.exe
rescript.exe)
(deps
../compiler/bsc/rescript_compiler_main.exe
../analysis/bin/main.exe
../tools/bin/main.exe
../build_system/rescript.exe)
(mode
(promote
(until-clean)
(into @rescript/win32-x64/bin)))
(action
(progn
(copy ../compiler/bsc/rescript_compiler_main.exe bsc.exe)
(copy ../analysis/bin/main.exe rescript-editor-analysis.exe)
(copy ../tools/bin/main.exe rescript-tools.exe)
(copy ../build_system/rescript.exe rescript.exe))))
7 changes: 3 additions & 4 deletions scripts/checkCompilerExes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @ts-check

// Verify that the compiler binaries in the platform npm package were
// produced by dune promotion from the current build (compiler/sync/dune is
// produced by dune promotion from the current build (packages/dune is
// their only producer). Fails when a binary is missing - e.g. this
// platform's promotion rule did not fire - or when a stale binary from an
// earlier build is still in place.
Expand All @@ -17,8 +17,7 @@ const syncDir = path.join(
"..",
"_build",
"default",
"compiler",
"sync",
"packages",
);

let ok = true;
Expand Down Expand Up @@ -53,7 +52,7 @@ for (const exe of executables) {

if (!ok) {
console.error(
"Dune promotion did not produce these binaries; check that this platform is covered by a rule in compiler/sync/dune.",
"Dune promotion did not produce these binaries; check that this platform is covered by a rule in packages/dune.",
);
process.exit(1);
}
Expand Down
10 changes: 1 addition & 9 deletions scripts/compilerBenchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,15 +631,7 @@ function measureProjectBuild(checkout, projectCheckout, results) {
`${JSON.stringify(config, null, 2)}\n`,
);
const scope = path.join(workDir, "node_modules", "@rescript");
// A base from before tests/dependencies/rescript-react moved to
// packages/rescript-react still has the project there; the next pull
// request in the stack drops that fallback.
const react =
[
path.join(projectCheckout, "packages", "rescript-react"),
path.join(projectCheckout, "tests", "dependencies", "rescript-react"),
].find(dir => fs.existsSync(dir)) ??
path.join(projectCheckout, "packages", "rescript-react");
const react = path.join(projectCheckout, "packages", "rescript-react");
copySources(path.join(react, "src"), path.join(scope, "react", "src"));
fs.copyFileSync(
path.join(react, "rescript.json"),
Expand Down
Loading