Skip to content

Commit

Permalink
Add 'exec'
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 30, 2023
1 parent b2c7b71 commit 2b9276b
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 220 deletions.
2 changes: 2 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 0.5.0 Change List

### Changes / improvements
- 'exec' directive to run scripts at compile time.
- Project key descriptions in --list command.
- Added `init-lib` to simplify library creation.
- Local `const` work like namespaced global `const`.
- Added `$$atomic_fetch_*` builtins.
Expand Down
3 changes: 3 additions & 0 deletions resources/testfragments/pwd2.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module pwd;

fn int getnum() => 3;
File renamed without changes.
3 changes: 3 additions & 0 deletions src/build/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ typedef struct BuildOptions_
const char *llvm_out;
const char *asm_out;
const char *obj_out;
const char *script_dir;
RelocModel reloc_model;
X86VectorCapability x86_vector_capability;
X86CpuSet x86_cpu_set;
Expand Down Expand Up @@ -429,6 +430,7 @@ typedef struct
const char *object_file_dir;
const char *ir_file_dir;
const char *asm_file_dir;
const char *script_dir;
bool run_after_compile;
bool generate_benchmark_runner;
bool generate_test_runner;
Expand Down Expand Up @@ -470,6 +472,7 @@ typedef struct
const char *testfn;
const char *cc;
const char *cflags;
const char **exec;
const char **csource_dirs;
const char **csources;
const char **feature_list;
Expand Down
6 changes: 6 additions & 0 deletions src/build/build_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ static const char *wincrt_linking[3] = {
[WIN_CRT_STATIC] = "static",
};

static const char *trust_level[3] = {
[TRUST_NONE] = "none",
[TRUST_INCLUDE] = "include",
[TRUST_FULL] = "full",
};

static const char *optsizes[3] = {
[SIZE_OPTIMIZATION_NONE] = "none",
[SIZE_OPTIMIZATION_SMALL] = "small",
Expand Down
17 changes: 14 additions & 3 deletions src/build/build_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ static void usage(void)
OUTPUT(" -O5 - Unsafe, highest optimization, fast maths, single module, emit debug info.");
OUTPUT(" -Os - Unsafe, high optimization, small code, single module, no debug info.");
OUTPUT(" -Oz - Unsafe, high optimization, tiny code, single module, no debug info.");
OUTPUT(" -t1 - Trust level 1 - don't allow $include nor $exec (default).");
OUTPUT(" -t2 - Trust level 2 - allow $include but not $exec / exec directives.");
OUTPUT(" -t3 - Trust level 3 - full trust, allow both include and exec.");
OUTPUT(" -D <name> - Add feature flag <name>.");
OUTPUT(" -U <name> - Remove feature flag <name>.");
OUTPUT(" --trust=<option> - Trust level: none (default), include ($include allowed), full ($exec / exec allowed).");
OUTPUT(" --build-dir <dir> - Override build output directory.");
OUTPUT(" --obj-out <dir> - Override object file output directory.");
OUTPUT(" --script-dir <dir> - Override the base directory for $exec.");
OUTPUT(" --llvm-out <dir> - Override llvm output directory for '--emit-llvm'.");
OUTPUT(" --emit-llvm - Emit LLVM IR as a .ll file per module.");
OUTPUT(" --asm-out <dir> - Override asm output directory for '--emit-asm'.");
Expand Down Expand Up @@ -887,6 +886,11 @@ static void parse_option(BuildOptions *options)
options->win.sdk = check_dir(next_arg());
return;
}
if ((argopt = match_argopt("trust")))
{
options->trust_level = (TrustLevel) parse_multi_option(argopt, 3, trust_level);
return;
}
if ((argopt = match_argopt("wincrt")))
{
options->win.crt_linking = (WinCrtLinking)parse_multi_option(argopt, 3, wincrt_linking);
Expand Down Expand Up @@ -916,6 +920,12 @@ static void parse_option(BuildOptions *options)
options->obj_out = next_arg();
return;
}
if (match_longopt("script-dir"))
{
if (at_end() || next_is_opt()) error_exit("error: --script-dir needs a directory.");
options->script_dir = next_arg();
return;
}
if (match_longopt("llvm-out"))
{
if (at_end() || next_is_opt()) error_exit("error: --llvm-out needs a directory.");
Expand Down Expand Up @@ -1044,6 +1054,7 @@ BuildOptions parse_arguments(int argc, const char *argv[])
.single_module = SINGLE_MODULE_NOT_SET,
.files = NULL,
.build_dir = NULL,
.script_dir = NULL,

};
for (int i = DIAG_NONE; i < DIAG_WARNING_TYPE; i++)
Expand Down
3 changes: 3 additions & 0 deletions src/build/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,16 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
target->object_file_dir = options->obj_out ? options->obj_out : target->build_dir;
target->ir_file_dir = options->llvm_out ? options->llvm_out : target->build_dir;
target->asm_file_dir = options->asm_out ? options->asm_out : target->build_dir;
target->script_dir = options->script_dir ? options->script_dir : target->script_dir;
}
else
{
target->build_dir = options->build_dir ? options->build_dir : "build";
target->object_file_dir = options->obj_out ? options->obj_out : file_append_path(target->build_dir, "tmp");
target->ir_file_dir = options->llvm_out ? options->llvm_out : file_append_path(target->build_dir, "llvm_ir");
target->asm_file_dir = options->asm_out ? options->asm_out : file_append_path(target->build_dir, "asm");
target->script_dir = options->script_dir ? options->script_dir : target->script_dir;
if (!target->script_dir) target->script_dir = "scripts";
}
switch (options->compile_option)
{
Expand Down
Loading

0 comments on commit 2b9276b

Please sign in to comment.