add out directory option

This commit is contained in:
koniifer 2025-01-01 20:37:20 +00:00
parent 9e7c78b5f1
commit 29889918eb
5 changed files with 36 additions and 8 deletions

View file

@ -4,6 +4,7 @@ use `./build -h` to see available arguments. supports:
- changing target
- custom linker (for `c_native`)
- running the executable (for `c_native`)
- setting output path
> [!IMPORTANT]
> all features, targets, etc, are provisional and subject to change

33
build
View file

@ -6,6 +6,7 @@ build_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
linker=""
target="c_native"
run=0
out="$build_dir/target/lily"
make_build_dir(){
if ! [ -e "$build_dir/target/build" ]; then
@ -16,6 +17,13 @@ make_build_dir(){
fi
}
check_out_dir(){
if ! [ -w "$(dirname "${out}")" ]; then
printf "ERROR: Out directory does not exist or is not writeable"
exit 1
fi
}
set_target(){
echo "target := @use(\"./$target.hb\")" > "$build_dir/src/lib/target/target.hb"
}
@ -27,6 +35,7 @@ while :; do
-r/--run: run (Available only on target=c_native)
-l/--linker: set linker (Available only on target=c_native)
-t/--target: set target (One of: c_native, hbvm_ableos)
-o/--out: set output path
-h/--help: show help
examples
./build -t hbvm_ableos
@ -68,6 +77,22 @@ examples
printf 'ERROR: "--linker" requires a non-empty option argument.\n' >&2
exit 1
;;
-o|--out)
if [ -n "${2:-}" ]; then
out="${2:-}"
shift
else
printf "ERROR: '--out' requires a non-empty option argument." >&2
exit 1
fi
;;
--out=?*)
out=${1#*=}
;;
--out=)
printf 'ERROR: "--out" requires a non-empty option argument.\n' >&2
exit 1
;;
--)
shift
break
@ -90,7 +115,6 @@ if [ $run = 1 ] && [ "$target" = "hbvm_ableos" ]; then
exit 1
fi
if ! command -v hbc > /dev/null 2>&1; then
printf "Error: hblang compiler not found. Install it with:
cargo +nightly install --git https://git.ablecorp.us/ableos/holey-bytes hbc --force" >&2
@ -112,10 +136,11 @@ if [ "$target" = "c_native" ]; then
fi
make_build_dir
check_out_dir
set_target
if hbc "$build_dir/src/main.hb" --backend-flags=opt_level=speed > "$build_dir/target/build/lily.o"; then
$linker "$build_dir/target/build/lily.o" -o "$build_dir/target/lily"
$linker "$build_dir/target/build/lily.o" -o "$out"
strip -s "$build_dir/target/lily"
else
echo "compilation failed :(" >&2
@ -126,8 +151,10 @@ if [ "$target" = "c_native" ]; then
fi
elif [ "$target" = "hbvm_ableos" ]; then
make_build_dir
check_out_dir
set_target
if ! hbc "$build_dir/src/main.hb" --target=unknown-virt-unknown > "$build_dir/target/build/lily.hbf"; then
if [ "$out" = "$build_dir/target/lily" ]; then out="$build_dir/target/lily.hbf"; fi
if ! hbc "$build_dir/src/main.hb" --target=unknown-virt-unknown > "$out"; then
echo "compilation failed :(" >&2
exit 1
fi

View file

@ -1,4 +1,4 @@
.{collections: .{Vec}, target, target_c_native, target_hbvm_ableos} := @use("lib.hb")
.{collections: .{Vec}, target, target_c_native, target_hbvm_ableos, null_pointer} := @use("lib.hb")
Allocation := struct {
ptr: ^void,
@ -67,7 +67,7 @@ RawAllocator := struct {
old_ptr: ^void,
size: uint,
old_size: uint,
$new := fn(): Self return .(@bitcast(0), @bitcast(0), 0, 0)
$new := fn(): Self return .(null_pointer(void), null_pointer(void), 0, 0)
deinit := fn(self: ^Self): void {
if target == target_c_native {
target.free(self.ptr)

View file

@ -1,4 +1,4 @@
.{log: .{LogLevel}} := @use("../lib.hb")
.{log: .{LogLevel}, null_pointer} := @use("../lib.hb")
$PAGE_SIZE := 4096
$MAX_ALLOC := 0xFF
@ -27,7 +27,7 @@ malloc := fn(size: uint): ?^void {
}
free := fn(ptr: ^void, size: uint): void {
if size == 0 | ptr == @bitcast(0) return;
if size == 0 | ptr == null_pointer(void) return;
pages := calculate_pages(size)
free_pages(ptr, pages)
}

View file

@ -14,7 +14,7 @@ main := fn(argc: uint, argv: []^void): uint {
loop if i == 5 break else {
defer i += 1
vec.push(i)
lily.log.print("pushed to vec\0")
lily.log.info("pushed to vec\0")
}
return 0