diff --git a/src/dune/exe_rules.ml b/src/dune/exe_rules.ml index ddaf1db80592..964b61e9926d 100644 --- a/src/dune/exe_rules.ml +++ b/src/dune/exe_rules.ml @@ -111,7 +111,12 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info let o_files = if not (Executables.has_stubs exes) then None - else + else ( + if List.mem Exe.Linkage.byte ~set:linkages then + User_error.raise ~loc:exes.buildable.loc + [ Pp.textf "Pure bytecode executables cannot contain C stubs." + ; Pp.textf "Did you forget to add `(modes exe)'?" + ]; let c_sources = Dir_contents.c_sources_of_executables dir_contents ~first_exe in @@ -122,6 +127,7 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info in Check_rules.add_files sctx ~dir o_files; Some o_files + ) in let requires_compile = Compilation_context.requires_compile cctx in Exe.build_and_link_many cctx ~programs ~linkages ~link_flags ?o_files diff --git a/test/blackbox-tests/test-cases/exes-with-c/dune b/test/blackbox-tests/test-cases/exes-with-c/dune index 203d2eecf0e8..a40cba7355ad 100644 --- a/test/blackbox-tests/test-cases/exes-with-c/dune +++ b/test/blackbox-tests/test-cases/exes-with-c/dune @@ -1,3 +1,4 @@ (executables (names aa bb) - (c_names foo)) + (c_names foo) + (modes exe))