Skip to content

Commit

Permalink
Add "name" project property to override the name of the resulting b…
Browse files Browse the repository at this point in the history
…inary. #1719
  • Loading branch information
lerno committed Dec 26, 2024
1 parent 9a9ff7f commit c3ebf51
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Deprecate cast-style conversion from integer <-> enum.
- Make deprecation an error in test mode.
- Add `--win-vs-dirs` to override VS detection dirs.
- Add `"name"` project property to override the name of the resulting binary. #1719

### Fixes
- Fix case trying to initialize a `char[*]*` from a String.
Expand Down
1 change: 1 addition & 0 deletions src/build/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ typedef struct
Library **library_list;
LibraryTarget **ccompiling_libraries;
const char *name;
const char *output_name;
const char *version;
const char *langrev;
const char **source_dirs;
Expand Down
1 change: 1 addition & 0 deletions src/build/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ void init_default_build_target(BuildTarget *target, BuildOptions *options)
*target = default_build_target;
target->source_dirs = options->files;
target->name = options->output_name;
target->output_name = options->output_name;
update_build_target_from_options(target, options);
}

Expand Down
4 changes: 4 additions & 0 deletions src/build/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const char* project_target_keys[][2] = {
{"macos-sdk-version", "Set the MacOS SDK compiled for." },
{"macossdk", "Set the directory for the MacOS SDK for cross compilation."},
{"memory-env", "Set the memory environment: normal, small, tiny, none."},
{"name", "Set the name to be different from the target name."},
{"no-entry", "Do not generate (or require) a main function."},
{"opt", "Optimization setting: O0, O1, O2, O3, O4, O5, Os, Oz."},
{"optlevel", "Code optimization level: none, less, more, max."},
Expand Down Expand Up @@ -247,6 +248,9 @@ static void load_into_build_target(const char *filename, JSONObject *json, const
target->feature.panic_level = (PanicLevel)get_valid_bool(filename, target_name, json, "panic-msg",
target->feature.panic_level);

// Overridden name
target->output_name = get_optional_string(filename, target_name, json, "name");

// Single module
target->single_module = (SingleModule) get_valid_bool(filename, target_name, json, "single-module", target->single_module);

Expand Down
1 change: 0 additions & 1 deletion src/build/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "../utils/json.h"

const char** get_project_dependency_directories();

const char** get_project_dependencies();

static void print_vec(const char *header, const char **vec, bool opt);
Expand Down
1 change: 1 addition & 0 deletions src/build/project_manipulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ static void view_target(const char *filename, const char *name, JSONObject *targ
print_opt_str("\tName", name);
TARGET_VIEW_MANDATORY_STRING("Type", "type");
TARGET_VIEW_STRING("Target language target", "langrev");
TARGET_VIEW_STRING("Target output name", "name");
TARGET_VIEW_STRING_ARRAY("Warnings used", "warnings");
TARGET_VIEW_STRING_ARRAY("Additional c3l library search paths", "dependency-search-paths");
TARGET_VIEW_STRING_ARRAY("c3l library search paths (override)", "dependency-search-paths-override");
Expand Down
25 changes: 12 additions & 13 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ static double compiler_link_time;
const char* c3_suffix_list[3] = { ".c3", ".c3t", ".c3i" };


static const char *out_name(void)
{
if (compiler.build.output_name) return compiler.build.output_name;
if (compiler.build.name) return compiler.build.name;
return NULL;
}

void compiler_init(BuildOptions *build_options)
{
// Process --path
Expand Down Expand Up @@ -150,12 +157,8 @@ void **tilde_gen(Module** modules, unsigned module_count)

const char *build_base_name(void)
{
const char *name;
if (compiler.build.name)
{
name = compiler.build.name;
}
else
const char *name = out_name();
if (!name)
{
Module **modules = compiler.context.module_list;
Module *main_module = (modules[0] == compiler.context.core_module && vec_size(modules) > 1) ? modules[1] : modules[0];
Expand All @@ -176,13 +179,9 @@ const char *build_base_name(void)

static const char *exe_name(void)
{
ASSERT0(compiler.build.name || compiler.context.main || compiler.build.no_entry);
const char *name;
if (compiler.build.name || compiler.build.no_entry)
{
name = compiler.build.name ? compiler.build.name : "out";
}
else
ASSERT0(compiler.build.output_name || compiler.build.name || compiler.context.main || compiler.build.no_entry);
const char *name = out_name();
if (!name)
{
Path *path = compiler.context.main->unit->module->name;
size_t first = 0;
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ void scratch_buffer_append_module(Module *module, bool is_export)

const char *module_create_object_file_name(Module *module)
{
if (compiler.build.single_module == SINGLE_MODULE_ON && compiler.build.name) return compiler.build.name;
if (compiler.build.single_module == SINGLE_MODULE_ON)
{
if (compiler.build.output_name) return compiler.build.output_name;
if (compiler.build.name) return compiler.build.name;
}
scratch_buffer_clear();
char c;
const char *name = module->name->module;
Expand Down

0 comments on commit c3ebf51

Please sign in to comment.