Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion resources/project_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@
"type": {
"type": "string",
"description": "Executable or library type for the target.",
"enum": ["executable", "static-lib", "dynamic-lib"]
"enum": ["executable", "static-lib", "dynamic-lib", "benchmark", "test", "object-files", "prepare"]
},
"name": {
"type": "string",
"description": "Override the output name for this target."
},
"extension": {
"type": "string",
"description": "Override the default file extension for the build output. Must start with '.'.",
"pattern": "^\\..*"
},
"preset": {
"type": "string",
"description": "Reference a preset configuration from a library dependency, format: 'library:preset'.",
"pattern": "^[a-z][a-z0-9_]{0,126}:[a-z][a-z0-9_]{0,126}$"
},
"dependencies": {
"type": "array",
Expand All @@ -97,6 +111,66 @@
"items": {
"type": "string"
}
},
"features": {
"type": "array",
"description": "Feature flags enabled for this target.",
"items": {
"type": "string"
}
},
"opt": {
"type": "string",
"description": "Optimization setting.",
"enum": ["O0", "O1", "O2", "O3", "O4", "O5", "Os", "Oz"]
},
"cpu": {
"type": "string",
"description": "CPU name, used for optimizations in the LLVM backend."
},
"cpu-flags": {
"type": "string",
"description": "Additional CPU flags to add or remove with the format '+avx,-sse'."
},
"target": {
"type": "string",
"description": "Compile for a particular architecture + OS target."
},
"linker": {
"type": "string",
"description": "Use 'builtin' for the builtin linker, 'cc' for the system linker or a path to a custom compiler."
},
"riscv-cpu": {
"type": "string",
"description": "Set general level of RISC-V CPU.",
"enum": ["rvi", "rvimac", "rvimafc", "rvgc", "rvgcv"]
},
"riscv-abi": {
"type": "string",
"description": "RISC-V ABI.",
"enum": ["int-only", "float", "double"]
},
"memory-env": {
"type": "string",
"description": "Memory environment.",
"enum": ["normal", "small", "tiny", "none"]
},
"reloc": {
"type": "string",
"description": "Relocation model.",
"enum": ["none", "pic", "PIC", "pie", "PIE"]
},
"use-stdlib": {
"type": "boolean",
"description": "Include the standard library."
},
"link-libc": {
"type": "boolean",
"description": "Link libc other default libraries."
},
"no-entry": {
"type": "boolean",
"description": "Do not generate or require a main function."
}
},
"required": ["type"]
Expand All @@ -112,6 +186,20 @@
"description": "CPU name, used for optimizations in the LLVM backend.",
"default": "generic"
},
"cpu-flags": {
"type": "string",
"description": "Additional CPU flags to add or remove with the format '+avx,-sse'."
},
"riscv-cpu": {
"type": "string",
"description": "Set general level of RISC-V CPU.",
"enum": ["rvi", "rvimac", "rvimafc", "rvgc", "rvgcv"]
},
"riscv-abi": {
"type": "string",
"description": "RISC-V ABI.",
"enum": ["int-only", "float", "double"]
},
"debug-info": {
"type": "string",
"description": "Debug information level.",
Expand Down Expand Up @@ -194,6 +282,11 @@
"description": "Use the system linker.",
"default": "cc"
},
"no-entry": {
"type": "boolean",
"description": "Do not generate or require a main function.",
"default": false
},
"use-stdlib": {
"type": "boolean",
"description": "Include the standard library.",
Expand Down
4 changes: 4 additions & 0 deletions resources/testproject/lib/clib3.c3l/clib3.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module clib3;

extern fn void hello_from_preset_feature();
extern fn void hello_from_local_feature();
6 changes: 6 additions & 0 deletions resources/testproject/lib/clib3.c3l/feature.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

void hello_from_preset_feature(void)
{
printf("Hello from clib3 preset feature!\n");
}
6 changes: 6 additions & 0 deletions resources/testproject/lib/clib3.c3l/local_feature.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

void hello_from_local_feature(void)
{
printf("Hello from clib3 local feature!\n");
}
30 changes: 30 additions & 0 deletions resources/testproject/lib/clib3.c3l/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"provides": "clib3",
"presets": {
"native_feature": {
"features": ["CLIB3_PRESET_TEST"]
},
"native_local_feature": {
"features": ["CLIB3_LOCAL_TEST"]
}
},
"features": {
"CLIB3_PRESET_TEST": {
"c-sources": ["feature.c"]
},
"CLIB3_LOCAL_TEST": {
"c-sources": ["local_feature.c"]
}
},
"targets": {
"macos-x64": {},
"macos-aarch64": {},
"netbsd-x64": {},
"netbsd-aarch64": {},
"openbsd-x64": {},
"linux-x64": {},
"windows-x64": {},
"android-aarch64": {},
"android-x86_64": {}
}
}
29 changes: 28 additions & 1 deletion resources/testproject/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"src"
],
"dependency-search-paths": [ "./lib" ],
"dependencies": ["clib", "clib2"],
"dependencies": ["clib", "clib2", "clib3"],
"cpu-flags": ",,",
"features": ["ABCD"],
"exec": ["scriptme.c3 myarg"],
Expand All @@ -26,6 +26,33 @@
],
"reloc": "PIE",
},
"hello_world_preset_feature": {
"type": "executable",
"preset": "clib3:native_feature",
"cc" : "cc",
"c-sources": [
"./csource/**"
],
"reloc": "PIE",
},
"hello_world_library_feature": {
"type": "executable",
"features": ["CLIB3_LOCAL_TEST"],
"cc" : "cc",
"c-sources": [
"./csource/**"
],
"reloc": "PIE",
},
"hello_world_preset_local_feature": {
"type": "executable",
"preset": "clib3:native_local_feature",
"cc" : "cc",
"c-sources": [
"./csource/**"
],
"reloc": "PIE",
},
"hello_world_win32": {
"type": "executable",
"c-include-dirs": [ "C:\\"],
Expand Down
4 changes: 3 additions & 1 deletion resources/testproject/src/hello/hello_world.c3
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module hello_world;
import std, bar, clib, clib2;
import std, bar, clib, clib2, clib3;

fn int test_doubler(int x) @if(env::WIN32) => x * x;
extern fn int test_doubler(int) @if(!env::WIN32);
Expand All @@ -23,5 +23,7 @@ fn int main()
if ($feature(ABCD)) io::printn("ABCD");
clib::hello_from_c();
clib2::hello_from_c_zip();
if ($feature(CLIB3_PRESET_TEST)) clib3::hello_from_preset_feature();
if ($feature(CLIB3_LOCAL_TEST)) clib3::hello_from_local_feature();
return 0;
}
12 changes: 12 additions & 0 deletions scripts/tools/ci_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ run_testproject() {
run_c3c run -vv $ARGS
run_c3c clean

echo "Running Test Project (library preset feature)..."
run_c3c -vv run hello_world_preset_feature $ARGS
run_c3c clean

echo "Running Test Project (library feature)..."
run_c3c -vv run hello_world_library_feature $ARGS
run_c3c clean

echo "Running Test Project (library preset with alternate feature)..."
run_c3c -vv run hello_world_preset_local_feature $ARGS
run_c3c clean

if [[ "$OS_MODE" == "windows" ]]; then
echo "Running Test Project (hello_world_win32)..."
run_c3c -vv --emit-llvm run hello_world_win32 $ARGS
Expand Down
2 changes: 2 additions & 0 deletions src/build/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DEFAULT_SWITCH_JUMP_MAX_SIZE (0x3FFF)
#define DEFAULT_PATH "."

typedef struct JSONObject_ JSONObject;

typedef enum
{
Expand Down Expand Up @@ -358,6 +359,7 @@ typedef struct Library__
const char **csource_dirs;
const char **cinclude_dirs;
WinCrtLinking win_crt;
JSONObject *features;
LibraryTarget *target_used;
LibraryTarget **targets;
} Library;
Expand Down
2 changes: 2 additions & 0 deletions src/build/build_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef struct
{
const char *file;
const char *target;
bool is_preset;
} BuildParseContext;

typedef struct
Expand Down Expand Up @@ -165,6 +166,7 @@ static const char *sanitize_modes[4] = {
JSONObject *project_json_load(const char **filename_ref);
Project *project_load(const char **filename_ref);
BuildTarget *project_select_target(const char *filename, Project *project, const char *optional_target);
JSONObject *read_library_manifest_for_path(const char *lib_path, const char **manifest_path_ref);

const char *get_string(BuildParseContext context, JSONObject *table, const char *key, const char *default_value);
int get_valid_bool(BuildParseContext context, JSONObject *json, const char *key, int default_val);
Expand Down
4 changes: 4 additions & 0 deletions src/build/common_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ void check_json_keys(const char* valid_keys[][2], size_t key_count, const char*
goto OK;
}
}
if (target_name && strncmp(target_name, "preset '", strlen("preset '")) == 0)
{
error_exit("Unknown parameter '%s' in '%s'. You can use '%s' to list all valid properties.", key, target_name, option);
}
WARNING("Unknown parameter '%s' in '%s'", key, target_name);
failed = true;
OK:;
Expand Down
Loading
Loading