add "build" command

This commit is contained in:
2026-07-04 20:04:09 +10:00
parent cb5991f342
commit dc8f7a5d76
3 changed files with 44 additions and 2 deletions

33
neb/src/build.py Normal file
View File

@@ -0,0 +1,33 @@
from .util import libs_dir, print_error_message
from .console import console
import sys
import os
import glob
import pathlib
import subprocess
def build(args):
comet_libs_dir = libs_dir()
folder_path = pathlib.Path(args.path).resolve()
folder_name = folder_path.name
out_path = os.path.join(comet_libs_dir, f"{folder_name}.cometlib")
c_files = glob.glob(f"{args.path}/*.c", recursive=True)
if len(c_files) == 0:
print_error_message(f"No C files were found in that directory! [d white]({folder_name})[/d white]")
sys.exit(1)
with console.status("Building", spinner="moon") as status:
try:
subprocess.run(
["gcc"] + c_files + ["-fPIC", "-shared", "-Wl,-undefined,symbol_lookup", "-o", out_path] + args.gcc_args,
check=True
)
except subprocess.CalledProcessError as e:
print_error_message(f"Failed to install [b]{folder_name}[/]: build failed!")
sys.exit(1)
console.log(f"[b][:white_check_mark:] Installed [green]{folder_name}[/green]![/b]")