From 98dccf4a0cdd9c2174bb60719d001b1377df0b9f Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 06:22:02 +0000 Subject: [PATCH 1/3] Keep the rules that fill the platform packages in packages/dune compiler/sync held only the dune rules that strip and copy every executable (bsc, rescript, the editor analysis and rescript-tools) into packages/@rescript//bin. That is packaging, not compiler code, and "sync" did not say so. The rules now sit next to the packages they fill; (dirs) keeps dune out of the npm packages. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- Makefile | 10 +- changes/packaging-rules-location.internal.md | 1 + compiler/dune | 1 - compiler/sync/dune | 120 ------------------ dune | 2 +- packages/dune | 123 +++++++++++++++++++ scripts/checkCompilerExes.js | 7 +- 7 files changed, 133 insertions(+), 131 deletions(-) create mode 100644 changes/packaging-rules-location.internal.md delete mode 100644 compiler/sync/dune create mode 100644 packages/dune diff --git a/Makefile b/Makefile index b2e86f0663a..3c09a666235 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ 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. @@ -88,12 +88,12 @@ $(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 $@ diff --git a/changes/packaging-rules-location.internal.md b/changes/packaging-rules-location.internal.md new file mode 100644 index 00000000000..dfbd5c5603e --- /dev/null +++ b/changes/packaging-rules-location.internal.md @@ -0,0 +1 @@ +- Move the rules that copy the executables into the platform packages from `compiler/sync/dune` to `packages/dune`. diff --git a/compiler/dune b/compiler/dune index f9bcdf52457..f022e5c8f5d 100644 --- a/compiler/dune +++ b/compiler/dune @@ -7,7 +7,6 @@ frontend gentype playground - sync syntax_cli typing version) diff --git a/compiler/sync/dune b/compiler/sync/dune deleted file mode 100644 index a0365bd9e71..00000000000 --- a/compiler/sync/dune +++ /dev/null @@ -1,120 +0,0 @@ -; Keep the npm platform package's binaries in sync with every `dune build`. -; -; The packages/@rescript//bin copies are what cli/*.js, the test -; harnesses, and the runtime build actually run; these promotion rules are -; their only producer (the Makefile no longer copies binaries). 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. - -(rule - (enabled_if - (and - (<> %{profile} browser) - (= %{system} macosx) - (= %{architecture} arm64))) - (targets - bsc.exe - rescript-editor-analysis.exe - rescript-tools.exe - rescript.exe) - (deps - ../bsc/rescript_compiler_main.exe - ../../analysis/bin/main.exe - ../../tools/bin/main.exe - ../../build_system/rescript.exe) - (mode - (promote - (until-clean) - (into ../../packages/@rescript/darwin-arm64/bin))) - (action - (progn - (run strip -o bsc.exe ../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 - ../bsc/rescript_compiler_main.exe - ../../analysis/bin/main.exe - ../../tools/bin/main.exe - ../../build_system/rescript.exe) - (mode - (promote - (until-clean) - (into ../../packages/@rescript/linux-arm64/bin))) - (action - (progn - (run strip -o bsc.exe ../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 - ../bsc/rescript_compiler_main.exe - ../../analysis/bin/main.exe - ../../tools/bin/main.exe - ../../build_system/rescript.exe) - (mode - (promote - (until-clean) - (into ../../packages/@rescript/linux-x64/bin))) - (action - (progn - (run strip -o bsc.exe ../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 - ../bsc/rescript_compiler_main.exe - ../../analysis/bin/main.exe - ../../tools/bin/main.exe - ../../build_system/rescript.exe) - (mode - (promote - (until-clean) - (into ../../packages/@rescript/win32-x64/bin))) - (action - (progn - (copy ../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)))) diff --git a/dune b/dune index be75bb511f5..feab592ec29 100644 --- a/dune +++ b/dune @@ -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. diff --git a/packages/dune b/packages/dune new file mode 100644 index 00000000000..d9837625b38 --- /dev/null +++ b/packages/dune @@ -0,0 +1,123 @@ +; Keep the npm platform packages' binaries in sync with every `dune build`. +; +; The @rescript//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 + (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)))) diff --git a/scripts/checkCompilerExes.js b/scripts/checkCompilerExes.js index 6531b256fbb..a889c795928 100644 --- a/scripts/checkCompilerExes.js +++ b/scripts/checkCompilerExes.js @@ -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. @@ -17,8 +17,7 @@ const syncDir = path.join( "..", "_build", "default", - "compiler", - "sync", + "packages", ); let ok = true; @@ -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); } From 86343215776d6361b0958d70d9ec848c60208c3a Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 07:29:48 +0000 Subject: [PATCH 2/3] Drop the benchmarks' fallback to tests/dependencies again The base of this pull request already has packages/rescript-react. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- scripts/compilerBenchmarks.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scripts/compilerBenchmarks.js b/scripts/compilerBenchmarks.js index 36cede0364f..9c77e29fabb 100644 --- a/scripts/compilerBenchmarks.js +++ b/scripts/compilerBenchmarks.js @@ -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"), From a918ba3c73b325b39fb100e88636fa3fdc6c0f2d Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 27 Nov 2026 09:04:41 +0000 Subject: [PATCH 3/3] Rebuild through make when packages/dune changes Make reran dune only for changes in the directories it scans, which covered compiler/sync/dune but not packages/dune, so editing the packaging rules alone left the binaries as they were. The root dune and dune-project, which hold the shared flags, were not tracked either. Answers the Codex review on #9448. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gLP8xKdoF8ZA2WZNCo Signed-off-by: Christoph Knittel --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3c09a666235..200c772eb4c 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,9 @@ $(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