Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed May 19, 2024
1 parent 44bea1b commit 0535203
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ pub fn build(b: *std.Build) !void {
const tracer_dep = b.dependency("tracer", .{});
exe.root_module.addImport("tracer", tracer_dep.module("tracer"));

exe.linkLibC();
// const python_step = b.step("cpython", "Builds libpython3.10 statically for the target");
// const libpython = try generateLibPython(b, target, optimize);

// const install_libpython = b.addInstallArtifact(libpython, .{});
// python_step.dependOn(&install_libpython.step);
// exe.step.dependOn(python_step);

const make_python = b.step("make-python", "Builds libpython statically for the target");
const libpython = generateLibPython(b, make_python, target, optimize);
exe.linkLibrary(libpython);
exe.linkLibC();
// exe.linkLibrary(libpython);
exe.linkSystemLibrary("python");
exe.addLibraryPath(b.path("vendor/"));

b.installArtifact(exe);
b.installArtifact(libpython);

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
Expand Down Expand Up @@ -105,22 +110,20 @@ fn generateOpCode(

fn generateLibPython(
b: *std.Build,
step: *std.Build.Step,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
_ = step; // autofix
) !*std.Build.Step.Compile {
const source = b.dependency("python", .{});

const lib = b.addStaticLibrary(.{
.name = "python3.10",
.target = target,
.optimize = optimize,
});

lib.linkLibC();
lib.root_module.addCMacro("PYTHONPATH", "\"\"");
lib.root_module.addCMacro("Py_BUILD_CORE_BUILTIN", "");

const source = b.dependency("python", .{});
const modulesConfig = b.addConfigHeader(.{
.style = .{ .autoconf = source.path("Modules/config.c.in") },
.include_path = "config.c",
Expand Down Expand Up @@ -212,7 +215,6 @@ fn generateLibPython(
"Python/hashtable.c",
"Python/import.c",
"Python/importdl.c",
"Python/initconfig.c",
"Python/marshal.c",
"Python/modsupport.c",
"Python/mysnprintf.c",
Expand All @@ -231,7 +233,6 @@ fn generateLibPython(
"Python/bootstrap_hash.c",
"Python/structmember.c",
"Python/symtable.c",
"Python/sysmodule.c",
"Python/thread.c",
"Python/traceback.c",
"Python/getopt.c",
Expand All @@ -243,7 +244,6 @@ fn generateLibPython(
"Python/fileutils.c",
"Python/suggestions.c",
"Python/dynload_shlib.c",
"Modules/getpath.c",
"Modules/main.c",
"Modules/gcmodule.c",
"Modules/posixmodule.c",
Expand Down Expand Up @@ -279,6 +279,24 @@ fn generateLibPython(
},
});

lib.addCSourceFile(.{
.file = source.path("Python/initconfig.c"),
.flags = &.{"-DPLATLIBDIR=\"lib\""},
});

lib.addCSourceFile(.{
.file = source.path("Python/sysmodule.c"),
.flags = &.{
"-DABIFLAGS=\"\"",
b.fmt("-DMULTIARCH=\"{s}\"", .{try target.result.linuxTriple(b.allocator)}),
},
});

lib.addCSourceFile(.{
.file = source.path("Modules/getpath.c"),
.flags = &.{"-DPYTHONPATH=\"\""},
});

const headers = b.addWriteFiles();
lib.addIncludePath(headers.getDirectory());

Expand Down

0 comments on commit 0535203

Please sign in to comment.