Skip to content

Commit

Permalink
Feature flags possible to add in project.json. See #991
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 15, 2023
1 parent d6e9985 commit 9233305
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions resources/testproject/hello_world.c3
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ fn int main()
printf("Hello World!\n");
bar::test();
printf("Hello double: %d\n", test_doubler(11));
if ($feature(ABCD)) io::printn("ABCD");

return 0;
}
2 changes: 2 additions & 0 deletions resources/testproject/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// libraries to use
"dependencies": [],

"features": ["ABCD"],

// c compiler
"cc": "cc",
// c sources
Expand Down
14 changes: 14 additions & 0 deletions src/build/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const char *project_default_keys[] = {
"winsdk",
"x86-stack-struct-return",
"x86vec",
"features"
};

const int project_default_keys_count = sizeof(project_default_keys) / sizeof(char*);
Expand Down Expand Up @@ -86,6 +87,7 @@ const char* project_target_keys[] = {
"winsdk",
"x86-stack-struct-return",
"x86vec",
"features",
};

const int project_target_keys_count = sizeof(project_target_keys) / sizeof(char*);
Expand Down Expand Up @@ -357,6 +359,18 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
int fpmath = get_valid_string_setting(json, "fp-math", type, fp_math, 0, 3, "strict, relaxed, fast");
if (fpmath > -1) target->feature.fp_math = fpmath;

const char **features = get_valid_array(json, "features", type, false);
if (features)
{
FOREACH_BEGIN(const char *feature, features)
if (!str_is_valid_constant(feature))
{
error_exit("Error reading 'features': '%s' is not a valid feature name.", feature);
}
vec_add(target->feature_list, feature);
FOREACH_END();
}

// x86vec
int x86vec = get_valid_string_setting(json, "x86vec", type, x86_vector_capability, 0, 6, "none, native, mmx, sse, avx or avx512");
if (x86vec > -1) target->feature.x86_vector_capability = x86vec;
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define COMPILER_VERSION "0.4.645"
#define COMPILER_VERSION "0.4.646"

0 comments on commit 9233305

Please sign in to comment.