Skip to content

Commit d8225d9

Browse files
committed
add zlib module
1 parent d63b9c0 commit d8225d9

File tree

3 files changed

+94
-70
lines changed

3 files changed

+94
-70
lines changed

Modules/config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern PyObject* PyInit__stat(void);
4545
extern PyObject* PyInit__symtable(void);
4646
extern PyObject* PyInit_pwd(void);
4747
extern PyObject* PyInit_xxsubtype(void);
48+
extern PyObject* PyInit_zlib(void);
4849

4950
/* -- ADDMODULE MARKER 1 -- */
5051

@@ -80,6 +81,7 @@ struct _inittab _PyImport_Inittab[] = {
8081
{"_symtable", PyInit__symtable},
8182
{"pwd", PyInit_pwd},
8283
{"xxsubtype", PyInit_xxsubtype},
84+
{"zlib", PyInit_zlib},
8385

8486
/* -- ADDMODULE MARKER 2 -- */
8587

build.zig

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
const std = @import("std");
22

3-
// Although this function looks imperative, note that its job is to
4-
// declaratively construct a build graph that will be executed by an external
5-
// runner.
63
pub fn build(b: *std.Build) void {
7-
// Standard target options allows the person running `zig build` to choose
8-
// what target to build for. Here we do not override the defaults, which
9-
// means any target is allowed, and the default is native. Other options
10-
// for restricting supported target set are available.
114
const target = b.standardTargetOptions(.{});
12-
13-
// Standard optimization options allow the person running `zig build` to select
14-
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15-
// set a preferred release mode, allowing the user to decide how to optimize.
165
const optimize = b.standardOptimizeOption(.{});
176

7+
const libz_dep = b.dependency("libz", .{
8+
.target = target,
9+
.optimize = optimize,
10+
});
11+
1812
const exe = b.addExecutable(.{
1913
.name = "cpython",
2014
.target = target,
2115
.optimize = optimize,
2216
});
17+
exe.linkLibrary(libz_dep.artifact("z"));
2318
exe.linkLibC();
2419

2520
exe.addIncludePath(b.path("Include/internal"));
@@ -629,22 +624,44 @@ pub fn build(b: *std.Build) void {
629624
}));
630625

631626
exe.addCSourceFiles(.{ .files = &.{
632-
"Programs/python.c",
627+
"Modules/_abc.c",
628+
"Modules/_codecsmodule.c",
629+
"Modules/_collectionsmodule.c",
630+
"Modules/_functoolsmodule.c",
631+
"Modules/_io/_iomodule.c",
632+
"Modules/_io/bufferedio.c",
633+
"Modules/_io/bytesio.c",
634+
"Modules/_io/fileio.c",
635+
"Modules/_io/iobase.c",
636+
"Modules/_io/stringio.c",
637+
"Modules/_io/textio.c",
638+
"Modules/_localemodule.c",
639+
"Modules/_operator.c",
640+
"Modules/_sre/sre.c",
641+
"Modules/_stat.c",
642+
"Modules/_threadmodule.c",
643+
"Modules/_tracemalloc.c",
644+
"Modules/_weakref.c",
645+
"Modules/atexitmodule.c",
646+
"Modules/config.c",
647+
"Modules/errnomodule.c",
648+
"Modules/faulthandler.c",
649+
"Modules/gcmodule.c",
633650
"Modules/getbuildinfo.c",
634-
"Parser/token.c",
635-
"Parser/pegen.c",
636-
"Parser/pegen_errors.c",
637-
"Parser/action_helpers.c",
638-
"Parser/parser.c",
639-
"Parser/string_parser.c",
640-
"Parser/peg_api.c",
641-
"Parser/myreadline.c",
642-
"Parser/tokenizer.c",
651+
"Modules/itertoolsmodule.c",
652+
"Modules/main.c",
653+
"Modules/posixmodule.c",
654+
"Modules/pwdmodule.c",
655+
"Modules/signalmodule.c",
656+
"Modules/symtablemodule.c",
657+
"Modules/timemodule.c",
658+
"Modules/xxsubtype.c",
659+
"Modules/zlibmodule.c",
643660
"Objects/abstract.c",
644661
"Objects/accu.c",
645662
"Objects/boolobject.c",
646-
"Objects/bytes_methods.c",
647663
"Objects/bytearrayobject.c",
664+
"Objects/bytes_methods.c",
648665
"Objects/bytesobject.c",
649666
"Objects/call.c",
650667
"Objects/capsule.c",
@@ -653,57 +670,74 @@ pub fn build(b: *std.Build) void {
653670
"Objects/codeobject.c",
654671
"Objects/complexobject.c",
655672
"Objects/descrobject.c",
673+
"Objects/dictobject.c",
656674
"Objects/enumobject.c",
657675
"Objects/exceptions.c",
658-
"Objects/genericaliasobject.c",
659-
"Objects/genobject.c",
660676
"Objects/fileobject.c",
661677
"Objects/floatobject.c",
662678
"Objects/frameobject.c",
663679
"Objects/funcobject.c",
680+
"Objects/genericaliasobject.c",
681+
"Objects/genobject.c",
664682
"Objects/interpreteridobject.c",
665683
"Objects/iterobject.c",
666684
"Objects/listobject.c",
667685
"Objects/longobject.c",
668-
"Objects/dictobject.c",
669-
"Objects/odictobject.c",
670686
"Objects/memoryobject.c",
671687
"Objects/methodobject.c",
672688
"Objects/moduleobject.c",
673689
"Objects/namespaceobject.c",
674690
"Objects/object.c",
675691
"Objects/obmalloc.c",
692+
"Objects/odictobject.c",
676693
"Objects/picklebufobject.c",
677694
"Objects/rangeobject.c",
678695
"Objects/setobject.c",
679696
"Objects/sliceobject.c",
680697
"Objects/structseq.c",
681698
"Objects/tupleobject.c",
682699
"Objects/typeobject.c",
683-
"Objects/unicodeobject.c",
684700
"Objects/unicodectype.c",
701+
"Objects/unicodeobject.c",
685702
"Objects/unionobject.c",
686703
"Objects/weakrefobject.c",
687-
"Python/_warnings.c",
704+
"Parser/action_helpers.c",
705+
"Parser/myreadline.c",
706+
"Parser/parser.c",
707+
"Parser/peg_api.c",
708+
"Parser/pegen.c",
709+
"Parser/pegen_errors.c",
710+
"Parser/string_parser.c",
711+
"Parser/token.c",
712+
"Parser/tokenizer.c",
713+
"Programs/python.c",
688714
"Python/Python-ast.c",
689715
"Python/Python-tokenize.c",
716+
"Python/_warnings.c",
690717
"Python/asdl.c",
691718
"Python/ast.c",
692719
"Python/ast_opt.c",
693720
"Python/ast_unparse.c",
694721
"Python/bltinmodule.c",
722+
"Python/bootstrap_hash.c",
695723
"Python/ceval.c",
696724
"Python/codecs.c",
697725
"Python/compile.c",
698726
"Python/context.c",
727+
"Python/deepfreeze/deepfreeze.c",
728+
"Python/dtoa.c",
699729
"Python/dynamic_annotations.c",
700730
"Python/errors.c",
731+
"Python/fileutils.c",
732+
"Python/formatter_unicode.c",
701733
"Python/frame.c",
734+
"Python/frozen.c",
702735
"Python/frozenmain.c",
703736
"Python/future.c",
704737
"Python/getargs.c",
705738
"Python/getcompiler.c",
706739
"Python/getcopyright.c",
740+
"Python/getopt.c",
707741
"Python/getplatform.c",
708742
"Python/getversion.c",
709743
"Python/hamt.c",
@@ -724,56 +758,18 @@ pub fn build(b: *std.Build) void {
724758
"Python/pylifecycle.c",
725759
"Python/pymath.c",
726760
"Python/pystate.c",
761+
"Python/pystrcmp.c",
762+
"Python/pystrhex.c",
763+
"Python/pystrtod.c",
727764
"Python/pythonrun.c",
728765
"Python/pytime.c",
729-
"Python/bootstrap_hash.c",
730766
"Python/specialize.c",
731767
"Python/structmember.c",
768+
"Python/suggestions.c",
732769
"Python/symtable.c",
733770
"Python/sysmodule.c",
734771
"Python/thread.c",
735772
"Python/traceback.c",
736-
"Python/getopt.c",
737-
"Python/pystrcmp.c",
738-
"Python/pystrtod.c",
739-
"Python/pystrhex.c",
740-
"Python/dtoa.c",
741-
"Python/formatter_unicode.c",
742-
"Python/fileutils.c",
743-
"Python/suggestions.c",
744-
"Modules/config.c",
745-
"Modules/main.c",
746-
"Modules/gcmodule.c",
747-
"Modules/atexitmodule.c",
748-
"Modules/faulthandler.c",
749-
"Modules/posixmodule.c",
750-
"Modules/signalmodule.c",
751-
"Modules/_tracemalloc.c",
752-
"Modules/_codecsmodule.c",
753-
"Modules/_collectionsmodule.c",
754-
"Modules/errnomodule.c",
755-
"Modules/_io/_iomodule.c",
756-
"Modules/_io/iobase.c",
757-
"Modules/_io/fileio.c",
758-
"Modules/_io/bytesio.c",
759-
"Modules/_io/bufferedio.c",
760-
"Modules/_io/textio.c",
761-
"Modules/_io/stringio.c",
762-
"Modules/itertoolsmodule.c",
763-
"Modules/_sre/sre.c",
764-
"Modules/_threadmodule.c",
765-
"Modules/timemodule.c",
766-
"Modules/_weakref.c",
767-
"Modules/_abc.c",
768-
"Modules/_functoolsmodule.c",
769-
"Modules/_localemodule.c",
770-
"Modules/_operator.c",
771-
"Modules/_stat.c",
772-
"Modules/symtablemodule.c",
773-
"Modules/pwdmodule.c",
774-
"Modules/xxsubtype.c",
775-
"Python/deepfreeze/deepfreeze.c",
776-
"Python/frozen.c",
777773
}, .flags = &.{
778774
"-fwrapv",
779775
"-std=c11",

build.zig.zon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.{
2+
.name = "cpython",
3+
.version = "3.11.4",
4+
5+
.minimum_zig_version = "0.12.0-dev.3639+9cfac4718",
6+
7+
.dependencies = .{
8+
.libz = .{
9+
.url = "https://github.com/allyourcodebase/zlib/archive/refs/tags/1.3.1-3.tar.gz",
10+
.hash = "1220138f4aba0c01e66b68ed9e1e1e74614c06e4743d88bc58af4f1c3dd0aae5fea7",
11+
},
12+
},
13+
14+
.paths = .{
15+
"Include",
16+
"LICENSE",
17+
"Lib",
18+
"Modules",
19+
"Objects",
20+
"Programs",
21+
"Python",
22+
"README.md",
23+
"build.zig",
24+
"build.zig.zon",
25+
},
26+
}

0 commit comments

Comments
 (0)