diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ee2b2ebf3..8ccb88b62 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,7 +42,7 @@ jobs: ..\build\${{ matrix.build_type }}\c3c.exe compile-run examples\ls.c3 ..\build\${{ matrix.build_type }}\c3c.exe compile-run examples\load_world.c3 ..\build\${{ matrix.build_type }}\c3c.exe compile-run examples\process.c3 - ..\build\${{ matrix.build_type }}\c3c.exe compile --test -g -O0 --threads 1 --target macos-x64 examples\constants.c3 + ..\build\${{ matrix.build_type }}\c3c.exe compile --no-entry --test -g -O0 --threads 1 --target macos-x64 examples\constants.c3 ..\build\${{ matrix.build_type }}\c3c.exe compile-run msvc_stack.c3 - name: Build testproject @@ -131,7 +131,7 @@ jobs: ../build/c3c compile-run --print-linking examples/fannkuch-redux.c3 ../build/c3c compile-run --print-linking examples/contextfree/boolerr.c3 ../build/c3c compile-run --print-linking examples/load_world.c3 - ../build/c3c compile --test -g -O0 --threads 1 --target macos-x64 examples/constants.c3 + ../build/c3c compile --no-entry --test -g -O0 --threads 1 --target macos-x64 examples/constants.c3 - name: Build testproject run: | @@ -187,7 +187,7 @@ jobs: ../build/c3c compile-run examples/fannkuch-redux.c3 ../build/c3c compile-run examples/contextfree/boolerr.c3 ../build/c3c compile-run examples/load_world.c3 - ../build/c3c compile --test -g -O0 --threads 1 --target macos-x64 examples/constants.c3 + ../build/c3c compile --no-entry --test -g -O0 --threads 1 --target macos-x64 examples/constants.c3 - name: Build testproject run: | cd resources/testproject @@ -281,9 +281,9 @@ jobs: ../build/c3c compile examples/fasta.c3 ../build/c3c compile examples/gameoflife.c3 ../build/c3c compile examples/hash.c3 - ../build/c3c compile examples/levenshtein.c3 + ../build/c3c compile-only examples/levenshtein.c3 ../build/c3c compile examples/load_world.c3 - ../build/c3c compile examples/map.c3 + ../build/c3c compile-only examples/map.c3 ../build/c3c compile examples/mandelbrot.c3 ../build/c3c compile examples/plus_minus.c3 ../build/c3c compile examples/nbodies.c3 @@ -403,8 +403,8 @@ jobs: run: | cd resources ../build/c3c compile examples/gameoflife.c3 - ../build/c3c compile examples/levenshtein.c3 - ../build/c3c compile examples/map.c3 + ../build/c3c compile-only examples/levenshtein.c3 + ../build/c3c compile-only examples/map.c3 ../build/c3c compile examples/mandelbrot.c3 ../build/c3c compile examples/plus_minus.c3 ../build/c3c compile examples/spectralnorm.c3 diff --git a/releasenotes.md b/releasenotes.md index d8889630d..2c6c89733 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -11,6 +11,7 @@ - `*-add` keys in targets in `manifest.json` and `project.json` are deprecated. - Made "add" the default for things like `sources`, `dependencies` and other keys in project and library files. - Give some symbol name suggestions when the path is matched. +- Don't generate .o files on `compile` and `compile-run` if there is no `main`. ### Fixes - Broken WASM library code. diff --git a/src/build/common_build.c b/src/build/common_build.c index 2d56eb3fc..b711308c7 100644 --- a/src/build/common_build.c +++ b/src/build/common_build.c @@ -16,7 +16,7 @@ void check_json_keys(const char* valid_keys[][2], size_t key_count, const char* { if (str_eq(key, deprecated_keys[j])) { - eprintf("'%s' is using the deprecated parameter '%s'", target_name, key); + eprintf("Note: Target '%s' is using the deprecated parameter '%s'\n", target_name, key); goto OK; } } diff --git a/src/build/libraries.c b/src/build/libraries.c index ac580be2b..5616b7707 100644 --- a/src/build/libraries.c +++ b/src/build/libraries.c @@ -65,20 +65,12 @@ static inline void parse_library_target(Library *library, LibraryTarget *target, JSONObject *object) { target->link_flags = get_string_array(library->dir, target_name, object, "linkflags", false); - if (target->link_flags) - { - eprintf("Library %s is using the deprecated `linkflags` parameter.", library->provides); - } - else + if (!target->link_flags) { target->link_flags = get_string_array(library->dir, target_name, object, "link-args", false); } target->linked_libs = get_string_array(library->dir, target_name, object, "linked-libs", false); - if (target->linked_libs) - { - eprintf("Library %s is using the deprecated `linked-libs` parameter.", library->provides); - } - else + if (!target->linked_libs) { target->linked_libs = get_string_array(library->dir, target_name, object, "linked-libraries", false); } diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 33a47c226..e1aefb642 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -435,6 +435,14 @@ void compiler_compile(void) error_exit("Failed to create output directory '%s'.", active_target.object_file_dir); } } + if (active_target.type == TARGET_TYPE_EXECUTABLE && !global_context.main && !active_target.no_entry) + { + error_exit("The 'main' function for the executable could not found, did you forget to add it?\n\n" + "- If you're using an alternative entry point you can suppress this message using '--no-entry'.\n" + "- If you want to build a library, use 'static-lib' or 'dynamic-lib'.\n" + "- If you just want to output object files for later linking, use 'compile-only'."); + } + switch (active_target.backend) { case BACKEND_LLVM: @@ -466,14 +474,8 @@ void compiler_compile(void) output_exe = exe_name(); break; case TARGET_TYPE_EXECUTABLE: - if (!global_context.main && !active_target.no_entry) - { - puts("No main function was found, compilation only object files are generated."); - } - else - { - output_exe = exe_name(); - } + assert(global_context.main || active_target.no_entry); + output_exe = exe_name(); break; case TARGET_TYPE_STATIC_LIB: output_static = static_lib_name(); diff --git a/test/src/tester.py b/test/src/tester.py index 0da805921..314f2c609 100644 --- a/test/src/tester.py +++ b/test/src/tester.py @@ -153,7 +153,7 @@ class Issues: self.current_file.close() print("- " + str(self.conf.numtests) + "/" + str( self.conf.numtests - self.conf.numsuccess - 1) + " " + self.sourcefile.filepath + ":", end="") - self.compile("--test compile " + self.current_file.filepath) + self.compile("--test compile-only " + self.current_file.filepath) if not self.has_errors: self.conf.numsuccess += 1 print(" Passed.") @@ -229,7 +229,7 @@ class Issues: if file.is_target: files_to_compile += " " + file.filepath - self.compile("--test compile " + files_to_compile) + self.compile("--test compile-only " + files_to_compile) if self.has_errors: return