hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f8a0aa4787622f87f4a2c56f42ccbfe5248b9029
parent df9facaea790c8fd1d490b15e983509b7ad32fcd
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri, 29 Sep 2023 22:19:18 -0400

driver: add -F freestanding flag

When used, the hosted main check in harec is disabled.

Also appends -m.main when +libc is supplied and -F isn't. This is
necessary for the newly added hosted environment check in harec to work
with +libc

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcmd/hare/build.ha | 2++
Mcmd/hare/build/types.ha | 2++
Mcmd/hare/build/util.ha | 6++++++
Mcmd/hare/main.ha | 3+++
4 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/cmd/hare/build.ha b/cmd/hare/build.ha @@ -57,6 +57,8 @@ fn build(name: str, cmd: *getopt::command) (void | error) = { const lexer = lex::init(&buf, "<-D argument>"); defer lex::finish(&lexer); append(ctx.defines, parse::define(&lexer)?); + case 'F' => + ctx.freestanding = true; case 'j' => match (strconv::stoz(opt.1)) { case let z: size => diff --git a/cmd/hare/build/types.ha b/cmd/hare/build/types.ha @@ -74,6 +74,8 @@ export type context = struct { test: bool, // whether submodules of the root module should have tests enabled submods: bool, + // if true, the main function won't be checked by harec + freestanding: bool, cmds: [NSTAGES]str, diff --git a/cmd/hare/build/util.ha b/cmd/hare/build/util.ha @@ -117,6 +117,12 @@ fn get_flags(ctx: *context, t: *task) ([]str | error) = { append(flags, strings::dup("-N")); append(flags, unparse::identstr(mod.ns)); }; + if (ctx.freestanding) { + append(flags, strings::dup("-m")); + append(flags, ""); + } else if (len(ctx.libs) != 0) { + append(flags, strings::dup("-m.main")); + }; append(flags, strings::dup("-M")); path::set(&buf, mod.path)?; for (let i = 0z; i < len(mod.ns); i += 1) { diff --git a/cmd/hare/main.ha b/cmd/hare/main.ha @@ -25,6 +25,9 @@ const help: []getopt::help = [ ('v', "print executed commands (specify twice to print arguments)"), ('a', "arch", "set target architecture"), ('D', "ident[:type]=value", "define a constant"), + // XXX: once cross-compiling to different targets (linux, + // freebsd, etc) is supported, we can probably merge -F with it + ('F', "build for freestanding environment"), ('j', "jobs", "set parallelism for build"), ('L', "libdir", "add directory to linker library search path"), ('l', "libname", "link with a system library"),