This commit is contained in:
IonutParau 2025-07-09 23:09:55 +02:00
parent 20a149cc28
commit 833d919066
2 changed files with 56 additions and 44 deletions

View File

@ -5,6 +5,7 @@ const LibBuildOpts = struct {
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
baremetal: bool,
bit32: bool,
};
fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
@ -34,6 +35,7 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
},
.flags = &.{
if(opts.baremetal) "-DNN_BAREMETAL" else "",
if(opts.bit32) "-DNN_BIT32" else "",
},
});
@ -108,8 +110,11 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
.baremetal = b.option(bool, "baremetal", "Compiles without libc integration") orelse false,
.bit32 = target.result.ptrBitWidth() == 32,
};
const noEmu = b.option(bool, "noEmu", "Disable compiling the emulator (fixes some build system quirks)") orelse false;
const includeFiles = b.addInstallHeaderFile(b.path("src/neonucleus.h"), "neonucleus.h");
const engineMod = addEngineSources(b, opts);
@ -134,6 +139,7 @@ pub fn build(b: *std.Build) void {
sharedStep.dependOn(&includeFiles.step);
sharedStep.dependOn(&b.addInstallArtifact(engineShared, .{}).step);
if(!noEmu) {
const emulator = b.addExecutable(.{
.name = "neonucleus",
.target = target,
@ -158,6 +164,7 @@ pub fn build(b: *std.Build) void {
},
.flags = &.{
if(opts.baremetal) "-DNN_BAREMETAL" else "",
if(opts.bit32) "-DNN_BIT32" else "",
},
});
compileTheRightLua(b, emulator, luaVer) catch unreachable;
@ -179,3 +186,4 @@ pub fn build(b: *std.Build) void {
run_step.dependOn(emulatorStep);
run_step.dependOn(&run_cmd.step);
}
}

View File

@ -10,11 +10,15 @@
#endif
#ifdef NN_BAREMETAL
#if defined(__LP64__) || defined(_LP64)
#ifdef NN_BIT32
typedef int nn_intptr_t;
typedef unsigned int nn_size_t;
#elif defined(__LP64__) || defined(_LP64)
// long is ptr sized
typedef long nn_intptr_t;
typedef unsigned long nn_size_t;
#else
#error "fuck you"
typedef long long nn_intptr_t;
typedef unsigned long long nn_size_t;
#endif