zig-zon 0.1.3__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zig-zon-0.2.0/PKG-INFO +60 -0
- zig-zon-0.2.0/build.zig +66 -0
- {zig_zon-0.1.3 → zig-zon-0.2.0}/build.zig.zon +4 -4
- zig-zon-0.2.0/setup.py +63 -0
- zig-zon-0.2.0/setup.zig.json +1 -0
- {zig_zon-0.1.3 → zig-zon-0.2.0}/src/zig_zon.zig +4 -3
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/README.md +7 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/build.zig +135 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/build.zig.zon +13 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/CPython.zig +198 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/LowerDashStringFormatter.zig +12 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/SDistStep.zig +77 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/VenvInstallTest.zig +76 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/extract_link_info.py +72 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/python.zig +50 -0
- zig_zon-0.1.3/MANIFEST.in +0 -2
- zig_zon-0.1.3/PKG-INFO +0 -67
- zig_zon-0.1.3/README.md +0 -48
- zig_zon-0.1.3/build.zig +0 -36
- zig_zon-0.1.3/pyproject.toml +0 -32
- zig_zon-0.1.3/sdistlist.json +0 -1
- zig_zon-0.1.3/setup.cfg +0 -4
- zig_zon-0.1.3/setup.py +0 -23
- zig_zon-0.1.3/src/test_zig_zon.py +0 -41
- zig_zon-0.1.3/zig_zon.egg-info/PKG-INFO +0 -67
- zig_zon-0.1.3/zig_zon.egg-info/SOURCES.txt +0 -13
- zig_zon-0.1.3/zig_zon.egg-info/dependency_links.txt +0 -1
- zig_zon-0.1.3/zig_zon.egg-info/top_level.txt +0 -1
- {zig_zon-0.1.3 → zig-zon-0.2.0/zig-pkg/zig_python_sdist}/LICENSE +0 -0
zig-zon-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zig-zon
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary:
|
|
5
|
+
Description-Content-Type: text/markdown
|
|
6
|
+
|
|
7
|
+
# Python Zig Zon Parser
|
|
8
|
+
|
|
9
|
+
A native python extension built with zig to parse zig-object-notation strings
|
|
10
|
+
into python objects.
|
|
11
|
+
|
|
12
|
+
On PyPi it is only distributed in source, and built during install.
|
|
13
|
+
It therefore needs to download the `ziglang` python package.
|
|
14
|
+
|
|
15
|
+
Depending on your OS, you may need the python development headers
|
|
16
|
+
(e.g. `python3-dev`) installed.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
install from source on pypi:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install zig-zon
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
running:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import zig_zon
|
|
30
|
+
parsed = zig_zon.parse('.{.allyourcode = .are_belong_to_us, .asd = 123}')
|
|
31
|
+
print(parsed)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or, look at the [test file](https://codeberg.org/dasimmet/python-zig-zon/src/branch/main/src/test_zig_zon.py)
|
|
35
|
+
|
|
36
|
+
## How it works
|
|
37
|
+
|
|
38
|
+
The `zig build` commands produces a python source distribution archive ready
|
|
39
|
+
for uploading to Pypi. It includes the sources of [zig-python-sdist](https://codeberg.org/dasimmet/zig-python-sdist)
|
|
40
|
+
and a custom `setup.py` that handles the build of the cpython extension.
|
|
41
|
+
|
|
42
|
+
When you run pip install, the source distribution is downloaded, and since
|
|
43
|
+
this source distribution depends on the `ziglang` python package at build time,
|
|
44
|
+
a `zig build` command is used to compile the extension.
|
|
45
|
+
|
|
46
|
+
## Developing
|
|
47
|
+
|
|
48
|
+
as opposed to other solutions for building cpython extensions in zig,
|
|
49
|
+
i want to develop this using:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
zig build
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
for linking against the local python installation [zig-python-sdist](https://codeberg.org/dasimmet/zig-python-sdist)
|
|
56
|
+
runs a python script that imports the cpython headers into zig's build cache,
|
|
57
|
+
run `translate-c` on the result and offers a `cpython` module to import
|
|
58
|
+
in our zig code.
|
|
59
|
+
On windows, the extension library is also linked against
|
|
60
|
+
the python runtime static lib and renamed to a `.pyd` file for importing.
|
zig-zon-0.2.0/build.zig
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const Build = std.Build;
|
|
3
|
+
const zig_python_sdist = @import("zig_python_sdist");
|
|
4
|
+
const zon = @import("build.zig.zon");
|
|
5
|
+
const CPython = @import("setuptools_zig_build").CPython;
|
|
6
|
+
|
|
7
|
+
pub fn build(b: *Build) void {
|
|
8
|
+
const target = b.standardTargetOptions(.{});
|
|
9
|
+
const optimize = b.standardOptimizeOption(.{});
|
|
10
|
+
|
|
11
|
+
// this target and section of our build is used at pip install time
|
|
12
|
+
const ext_install_step = b.step("pyext", "build python extension module");
|
|
13
|
+
{
|
|
14
|
+
const cpython = zig_python_sdist.CPython.find(b);
|
|
15
|
+
|
|
16
|
+
const lib = b.addLibrary(.{
|
|
17
|
+
.name = "zig_zon",
|
|
18
|
+
.root_module = b.addModule("zig_zon", .{
|
|
19
|
+
.root_source_file = b.path("src/zig_zon.zig"),
|
|
20
|
+
.target = target,
|
|
21
|
+
.optimize = optimize,
|
|
22
|
+
}),
|
|
23
|
+
.linkage = .dynamic,
|
|
24
|
+
});
|
|
25
|
+
cpython.link(b, .{
|
|
26
|
+
.lib = lib,
|
|
27
|
+
.version = zon.version,
|
|
28
|
+
.optimize = .ReleaseSmall,
|
|
29
|
+
});
|
|
30
|
+
const ext_install = zig_python_sdist.CPython.installExtLib(b, lib);
|
|
31
|
+
|
|
32
|
+
ext_install_step.dependOn(&ext_install.step);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// this generates a python sdist archive
|
|
36
|
+
const sdist = zig_python_sdist.create(b, .{
|
|
37
|
+
.name = "zig-zon",
|
|
38
|
+
.version = zon.version,
|
|
39
|
+
.description = b.path("README.md"),
|
|
40
|
+
.build_args = &.{ ext_install_step.name, b.fmt("-Doptimize={s}", .{@tagName(optimize)}) },
|
|
41
|
+
.files = &.{
|
|
42
|
+
.{ .src = b.path("build.zig.zon"), .dest = "build.zig.zon" },
|
|
43
|
+
.{ .src = b.path("build.zig"), .dest = "build.zig" },
|
|
44
|
+
.{ .src = b.path("src/zig_zon.zig"), .dest = "src/zig_zon.zig" },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const sdistfile = b.addInstallFileWithDir(
|
|
49
|
+
sdist.getEmittedArchive(),
|
|
50
|
+
.{ .custom = "src" },
|
|
51
|
+
sdist.basename,
|
|
52
|
+
);
|
|
53
|
+
b.getInstallStep().dependOn(&sdistfile.step);
|
|
54
|
+
|
|
55
|
+
// we can use a python virtual environment inside
|
|
56
|
+
// the zig cache to test pip installation
|
|
57
|
+
const test_pip_install = zig_python_sdist.VenvInstallTest.create(
|
|
58
|
+
b,
|
|
59
|
+
.{
|
|
60
|
+
.sdist = sdist.getEmittedArchive(),
|
|
61
|
+
.test_py = b.path("src/test_zig_zon.py"),
|
|
62
|
+
.no_clean = b.option(bool, "pip-no-clean", "dont cleanup pip temp dirs") orelse false,
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
b.step("test-pip-install", "").dependOn(test_pip_install.step);
|
|
66
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
.{
|
|
2
2
|
.name = .python_zig_zon,
|
|
3
3
|
.fingerprint = 0x3d332656a3644fc9,
|
|
4
|
-
.version = "0.
|
|
4
|
+
.version = "0.2.0",
|
|
5
5
|
.minimum_zig_version = "0.16.0",
|
|
6
6
|
.dependencies = .{
|
|
7
|
-
.
|
|
8
|
-
.url = "git+https://codeberg.org/dasimmet/
|
|
9
|
-
.hash = "
|
|
7
|
+
.zig_python_sdist = .{
|
|
8
|
+
.url = "git+https://codeberg.org/dasimmet/zig-python-sdist.git#509be1fcce025754c7bc6f0647802e79e195778b",
|
|
9
|
+
.hash = "zig_python_sdist-0.0.1-wjgdOo-NAAAH7qc0ulwksgbdgfrZ8bP4EhMw_ZRN1UtS",
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
.paths = .{
|
zig-zon-0.2.0/setup.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
from setuptools import setup
|
|
4
|
+
from setuptools.command.bdist_wheel import bdist_wheel
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import os
|
|
8
|
+
import json
|
|
9
|
+
import glob
|
|
10
|
+
import shutil
|
|
11
|
+
|
|
12
|
+
with open("setup.zig.json") as fd:
|
|
13
|
+
setup_json = json.load(fd)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def mkversion(v, need_release=False):
|
|
17
|
+
if need_release:
|
|
18
|
+
assert v['pre'] == None, "cannot use version with pre: " + str(v)
|
|
19
|
+
assert v['build'] == None, "cannot use version with build: " + str(v)
|
|
20
|
+
return str(v['major']) + '.' + str(
|
|
21
|
+
v['minor']) + '.' + str(v['patch'])
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ZigBuildWheel(bdist_wheel):
|
|
25
|
+
def run(self, *args, **kwargs):
|
|
26
|
+
|
|
27
|
+
import ziglang
|
|
28
|
+
zig_exe = os.path.join(
|
|
29
|
+
os.path.dirname(ziglang.__file__), "zig")
|
|
30
|
+
|
|
31
|
+
cwd = os.getcwd()
|
|
32
|
+
print("zig build dir:", cwd, file=sys.stderr)
|
|
33
|
+
print("using zig exe:", zig_exe, file=sys.stderr)
|
|
34
|
+
|
|
35
|
+
extra_build_args = setup_json['build']['args']
|
|
36
|
+
build_cmd = [zig_exe, 'build'] + extra_build_args
|
|
37
|
+
|
|
38
|
+
print("zig build:", build_cmd, file=sys.stderr)
|
|
39
|
+
subprocess.check_call(build_cmd)
|
|
40
|
+
|
|
41
|
+
os.makedirs(self.bdist_dir, exist_ok=True)
|
|
42
|
+
artifacts = glob.glob("zig-out/lib/*")
|
|
43
|
+
if len(artifacts) == 0:
|
|
44
|
+
raise Exception(
|
|
45
|
+
'no zig artifacts found in {}/zig-out/lib/*'.format(cwd))
|
|
46
|
+
|
|
47
|
+
for it in artifacts:
|
|
48
|
+
shutil.copyfile(it, os.path.join(
|
|
49
|
+
self.bdist_dir, os.path.basename(it)))
|
|
50
|
+
|
|
51
|
+
return super().run(*args, **kwargs)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
setup(
|
|
55
|
+
name=setup_json['name'],
|
|
56
|
+
version=mkversion(setup_json['version']),
|
|
57
|
+
cmdclass={'bdist_wheel': ZigBuildWheel},
|
|
58
|
+
setup_requires=[
|
|
59
|
+
"setuptools",
|
|
60
|
+
"wheel",
|
|
61
|
+
"ziglang==" + mkversion(setup_json['zig_version'], need_release=True),
|
|
62
|
+
],
|
|
63
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"zig_zon","version":{"major":0,"minor":2,"patch":0,"pre":null,"build":null},"zig_version":{"major":0,"minor":16,"patch":0,"pre":null,"build":null},"build":{"args":["pyext","-Doptimize=Debug","--fork=zig-pkg/zig_python_sdist"]}}
|
|
@@ -4,8 +4,8 @@ const Allocator = std.mem.Allocator;
|
|
|
4
4
|
const assert = std.debug.assert;
|
|
5
5
|
const ZonGen = std.zig.ZonGen;
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const c =
|
|
7
|
+
const cpython = @import("cpython");
|
|
8
|
+
const c = cpython.c;
|
|
9
9
|
const PyObject = c.PyObject;
|
|
10
10
|
|
|
11
11
|
pub var methods = [_]c.PyMethodDef{
|
|
@@ -25,7 +25,8 @@ pub var zigmodule = c.PyModuleDef{
|
|
|
25
25
|
|
|
26
26
|
pub export fn PyInit_zig_zon() [*c]c.PyObject {
|
|
27
27
|
const mod = c.PyModule_Create(&zigmodule);
|
|
28
|
-
|
|
28
|
+
cpython.addVersion(mod);
|
|
29
|
+
cpython.addZigTargetTriple(mod);
|
|
29
30
|
return mod;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const Build = std.Build;
|
|
3
|
+
const LazyPath = Build.LazyPath;
|
|
4
|
+
const zon = @import("build.zig.zon");
|
|
5
|
+
|
|
6
|
+
pub const CPython = @import("src/build/CPython.zig");
|
|
7
|
+
pub const VenvInstallTest = @import("src/build/VenvInstallTest.zig");
|
|
8
|
+
pub const SDistStep = @import("src/build/SDistStep.zig");
|
|
9
|
+
|
|
10
|
+
pub fn build(b: *Build) void {
|
|
11
|
+
const target = b.standardTargetOptions(.{});
|
|
12
|
+
const optimize = b.standardOptimizeOption(.{});
|
|
13
|
+
|
|
14
|
+
const mod = b.addModule("sdist-builder", .{
|
|
15
|
+
.root_source_file = b.path("src/sdist_builder.zig"),
|
|
16
|
+
.target = target,
|
|
17
|
+
.optimize = optimize,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const exe = b.addExecutable(.{
|
|
21
|
+
.name = "sdist-builder",
|
|
22
|
+
.root_module = mod,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
b.installArtifact(exe);
|
|
26
|
+
|
|
27
|
+
const cpython = CPython.find(b);
|
|
28
|
+
|
|
29
|
+
const sdist_dummy = b.addLibrary(.{
|
|
30
|
+
.name = "sdist_dummy",
|
|
31
|
+
.root_module = b.createModule(.{
|
|
32
|
+
.root_source_file = b.path("example/sdist_dummy.zig"),
|
|
33
|
+
.target = target,
|
|
34
|
+
.optimize = optimize,
|
|
35
|
+
}),
|
|
36
|
+
.linkage = .dynamic,
|
|
37
|
+
});
|
|
38
|
+
cpython.link(b, .{
|
|
39
|
+
.lib = sdist_dummy,
|
|
40
|
+
.version = zon.version,
|
|
41
|
+
});
|
|
42
|
+
const install_ext = CPython.installExtLib(b, sdist_dummy);
|
|
43
|
+
|
|
44
|
+
const build_ext_step = b.step("build-ext", "build the sdist dummy python module");
|
|
45
|
+
build_ext_step.dependOn(&install_ext.step);
|
|
46
|
+
|
|
47
|
+
const sdist = SDistStep.createInternal(b, .{
|
|
48
|
+
.sdist_builder = exe,
|
|
49
|
+
.name = "zig-python-sdist-dummy",
|
|
50
|
+
.version = zon.version,
|
|
51
|
+
.description = b.path("README.md"),
|
|
52
|
+
.build_args = &.{build_ext_step.name}, // target name for pip zig build command
|
|
53
|
+
.files = &.{
|
|
54
|
+
.{ .src = b.path("build.zig.zon"), .dest = "build.zig.zon" },
|
|
55
|
+
.{ .src = b.path("build.zig"), .dest = "build.zig" },
|
|
56
|
+
.{ .src = b.path("example/sdist_dummy.zig"), .dest = "example/sdist_dummy.zig" },
|
|
57
|
+
},
|
|
58
|
+
.directories = &.{
|
|
59
|
+
.{ .src = b.path("src"), .dest = "src" },
|
|
60
|
+
.{ .src = b.path("src/build"), .dest = "src/build" },
|
|
61
|
+
},
|
|
62
|
+
.zig_version = std.SemanticVersion.parse("0.16.0") catch unreachable,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const sdistfile = b.addInstallFileWithDir(
|
|
66
|
+
sdist.getEmittedArchive(),
|
|
67
|
+
.{ .custom = "src" },
|
|
68
|
+
sdist.basename,
|
|
69
|
+
);
|
|
70
|
+
b.getInstallStep().dependOn(&sdistfile.step);
|
|
71
|
+
|
|
72
|
+
const test_pip_install = VenvInstallTest.create(
|
|
73
|
+
b,
|
|
74
|
+
.{
|
|
75
|
+
.sdist = sdist.getEmittedArchive(),
|
|
76
|
+
.test_py = b.path("example/test_ext.py"),
|
|
77
|
+
.no_clean = b.option(bool, "pip-no-clean", "cleanup pip temp dirs") orelse false,
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
b.step("test-pip-install", "").dependOn(test_pip_install.step);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn create(b: *Build, options: SDistStep.Options) *SDistStep {
|
|
84
|
+
var opt = options;
|
|
85
|
+
const sdist = b.dependencyFromBuildZig(@This(), .{
|
|
86
|
+
.target = b.graph.host,
|
|
87
|
+
.optimize = .Debug,
|
|
88
|
+
});
|
|
89
|
+
opt.sdist_builder = opt.sdist_builder orelse sdist.artifact("sdist-builder");
|
|
90
|
+
|
|
91
|
+
{
|
|
92
|
+
var files: std.ArrayList(SDistStep.Content) = .empty;
|
|
93
|
+
const extra_files: []const SDistStep.Content = &.{
|
|
94
|
+
.{ .src = sdist.path("build.zig.zon"), .dest = "zig-pkg/zig_python_sdist/build.zig.zon" },
|
|
95
|
+
.{ .src = sdist.path("build.zig"), .dest = "zig-pkg/zig_python_sdist/build.zig" },
|
|
96
|
+
.{ .src = sdist.path("README.md"), .dest = "zig-pkg/zig_python_sdist/README.md" },
|
|
97
|
+
.{ .src = sdist.path("LICENSE"), .dest = "zig-pkg/zig_python_sdist/LICENSE" },
|
|
98
|
+
};
|
|
99
|
+
files.ensureTotalCapacity(
|
|
100
|
+
b.allocator,
|
|
101
|
+
opt.files.len + extra_files.len,
|
|
102
|
+
) catch @panic("OOM");
|
|
103
|
+
files.appendSliceAssumeCapacity(opt.files);
|
|
104
|
+
files.appendSliceAssumeCapacity(extra_files);
|
|
105
|
+
opt.files = files.toOwnedSlice(b.allocator) catch @panic("OOM");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
var dirs: std.ArrayList(SDistStep.Content) = .empty;
|
|
110
|
+
const extra_dirs: []const SDistStep.Content = &.{
|
|
111
|
+
// .{ .src = sdist.path("src"), .dest = "zig-pkg/zig_python_sdist/src" },
|
|
112
|
+
.{ .src = sdist.path("src/build"), .dest = "zig-pkg/zig_python_sdist/src/build" },
|
|
113
|
+
};
|
|
114
|
+
dirs.ensureTotalCapacity(
|
|
115
|
+
b.allocator,
|
|
116
|
+
opt.directories.len + extra_dirs.len,
|
|
117
|
+
) catch @panic("OOM");
|
|
118
|
+
dirs.appendSliceAssumeCapacity(opt.directories);
|
|
119
|
+
dirs.appendSliceAssumeCapacity(extra_dirs);
|
|
120
|
+
opt.directories = dirs.toOwnedSlice(b.allocator) catch @panic("OOM");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
{
|
|
124
|
+
var args: std.ArrayList([]const u8) = .empty;
|
|
125
|
+
args.ensureTotalCapacity(
|
|
126
|
+
b.allocator,
|
|
127
|
+
opt.build_args.len + 1,
|
|
128
|
+
) catch @panic("OOM");
|
|
129
|
+
args.appendSliceAssumeCapacity(opt.build_args);
|
|
130
|
+
args.appendAssumeCapacity("--fork=zig-pkg/zig_python_sdist");
|
|
131
|
+
opt.build_args = args.toOwnedSlice(b.allocator) catch @panic("OOM");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return SDistStep.createInternal(b, opt);
|
|
135
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
3
|
+
const Build = std.Build;
|
|
4
|
+
const fs = std.fs;
|
|
5
|
+
const mem = std.mem;
|
|
6
|
+
|
|
7
|
+
pub const CPython = @This();
|
|
8
|
+
|
|
9
|
+
exe: Build.LazyPath,
|
|
10
|
+
|
|
11
|
+
/// adds a `python` option to the build. if not provided, tries to find `python` in PATH
|
|
12
|
+
pub fn findAddOption(b: *Build) *CPython {
|
|
13
|
+
if (b.option(
|
|
14
|
+
Build.LazyPath,
|
|
15
|
+
"python",
|
|
16
|
+
"path to the cpython interpreter executable",
|
|
17
|
+
)) |opt| {
|
|
18
|
+
const self = b.allocator.create(CPython) catch @panic("OOM");
|
|
19
|
+
self.* = .{
|
|
20
|
+
.exe = opt,
|
|
21
|
+
};
|
|
22
|
+
return self;
|
|
23
|
+
} else return find(b);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
pub fn find(b: *Build) *CPython {
|
|
27
|
+
const self = b.allocator.create(CPython) catch @panic("OOM");
|
|
28
|
+
const exe_path = findProgramCompat(b, &.{
|
|
29
|
+
"python",
|
|
30
|
+
"python3",
|
|
31
|
+
}) orelse {
|
|
32
|
+
const err_wf = b.addWriteFiles();
|
|
33
|
+
const err_step = b.addFail("finding python failed. please provide a path to the exe using -Dpython=");
|
|
34
|
+
err_wf.step.dependOn(&err_step.step);
|
|
35
|
+
self.* = .{ .exe = err_wf.getDirectory() };
|
|
36
|
+
return self;
|
|
37
|
+
};
|
|
38
|
+
self.* = .{
|
|
39
|
+
.exe = .{
|
|
40
|
+
.cwd_relative = exe_path,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return self;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub const LinkOptions = struct {
|
|
47
|
+
/// library to link against libpython
|
|
48
|
+
lib: *std.Build.Step.Compile,
|
|
49
|
+
version: ?[]const u8 = null,
|
|
50
|
+
/// optimize mode for the c module. will fall back to lib's optimize mode.
|
|
51
|
+
optimize: ?std.builtin.OptimizeMode = null,
|
|
52
|
+
macros: []const [2][]const u8 = &default_macros,
|
|
53
|
+
pub const default_macros = .{
|
|
54
|
+
.{ "Py_LIMITED_API", "0x03060500" }, // use the limited api from 3.6.5
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
pub fn generateIncludeDir(self: CPython, b: *Build) Build.LazyPath {
|
|
59
|
+
const extract_link_info = Build.Step.Run.create(b, "python header extraction run");
|
|
60
|
+
extract_link_info.addFileArg(self.exe);
|
|
61
|
+
const wf = b.addWriteFiles();
|
|
62
|
+
extract_link_info.addFileArg(wf.add("extract_link_info.py", @embedFile("extract_link_info.py")));
|
|
63
|
+
return extract_link_info.addOutputDirectoryArg("include");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
pub fn installExtLib(b: *Build, lib: *Build.Step.Compile) *Build.Step.InstallFile {
|
|
67
|
+
const ext_lib_name = lib_ext_name(b, lib);
|
|
68
|
+
return b.addInstallLibFile(lib.getEmittedBin(), ext_lib_name);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pub fn link(self: CPython, b: *Build, options: LinkOptions) void {
|
|
72
|
+
const target = Build.ResolvedTarget{
|
|
73
|
+
.query = .{},
|
|
74
|
+
.result = options.lib.rootModuleTarget(),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const python_inc = self.generateIncludeDir(b);
|
|
78
|
+
|
|
79
|
+
const cpython = b.addTranslateC(.{
|
|
80
|
+
.root_source_file = python_inc.path(b, "Zig_Python_With_Hexver.h"),
|
|
81
|
+
.optimize = options.optimize orelse options.lib.root_module.optimize orelse .ReleaseSafe,
|
|
82
|
+
.target = target,
|
|
83
|
+
});
|
|
84
|
+
cpython.addIncludePath(python_inc);
|
|
85
|
+
|
|
86
|
+
const wf = b.addWriteFiles();
|
|
87
|
+
|
|
88
|
+
const pymod = b.createModule(.{
|
|
89
|
+
.root_source_file = wf.add("python.zig", @embedFile("python.zig")),
|
|
90
|
+
.imports = &.{
|
|
91
|
+
.{ .name = "c", .module = cpython.createModule() },
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (options.version) |version| {
|
|
96
|
+
pymod.addImport("version", b.createModule(.{
|
|
97
|
+
.root_source_file = wf.add("version.txt", version),
|
|
98
|
+
}));
|
|
99
|
+
} else {
|
|
100
|
+
pymod.addImport("version", b.createModule(.{
|
|
101
|
+
.root_source_file = wf.add("version.txt", "version not provided at configure time!"),
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (options.macros) |macro| {
|
|
106
|
+
cpython.defineCMacro(macro[0], macro[1]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (target.result.os.tag == .windows) {
|
|
110
|
+
options.lib.root_module.addLibraryPath(python_inc);
|
|
111
|
+
options.lib.root_module.linkSystemLibrary("python", .{});
|
|
112
|
+
}
|
|
113
|
+
options.lib.root_module.addImport(
|
|
114
|
+
"cpython",
|
|
115
|
+
pymod,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
pub fn lib_ext_name(b: *Build, lib: *Build.Step.Compile) []const u8 {
|
|
120
|
+
const target = lib.rootModuleTarget();
|
|
121
|
+
return if (target.os.tag == .windows)
|
|
122
|
+
b.fmt("{s}.pyd", .{lib.name})
|
|
123
|
+
else
|
|
124
|
+
b.fmt("{s}.so", .{lib.name});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pub fn run_test(
|
|
128
|
+
self: CPython,
|
|
129
|
+
b: *Build,
|
|
130
|
+
lib: *Build.Step.Compile,
|
|
131
|
+
test_py_file: Build.LazyPath,
|
|
132
|
+
) *Build.Step.Run {
|
|
133
|
+
const wf = b.addWriteFiles();
|
|
134
|
+
const python_runner = wf.add("python-runner.zig", @embedFile("python-runner.zig"));
|
|
135
|
+
|
|
136
|
+
const runner = b.addExecutable(.{
|
|
137
|
+
.name = "python-runner",
|
|
138
|
+
.root_module = b.createModule(.{
|
|
139
|
+
.root_source_file = python_runner,
|
|
140
|
+
.target = b.graph.host,
|
|
141
|
+
.optimize = .ReleaseSmall,
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
const run_step = b.addRunArtifact(runner);
|
|
145
|
+
const python_ext = writeExtensionFile(b, lib);
|
|
146
|
+
run_step.addFileArg(self.exe);
|
|
147
|
+
run_step.addDirectoryArg(python_ext.dirname());
|
|
148
|
+
run_step.addFileArg(test_py_file);
|
|
149
|
+
run_step.has_side_effects = true;
|
|
150
|
+
return run_step;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
pub fn writeExtensionFile(b: *Build, lib: *Build.Step.Compile) Build.LazyPath {
|
|
154
|
+
const ext_lib_name = lib_ext_name(b, lib);
|
|
155
|
+
const wf = b.addWriteFiles();
|
|
156
|
+
return wf.addCopyFile(lib.getEmittedBin(), ext_lib_name);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
pub fn addSdistList(b: *Build) void {
|
|
160
|
+
const wf = b.addWriteFiles();
|
|
161
|
+
var wr: std.Io.Writer.Allocating = .init(b.allocator);
|
|
162
|
+
var jw: std.json.Stringify = .{ .writer = &wr.writer };
|
|
163
|
+
jw.beginObject() catch @panic("OOM");
|
|
164
|
+
if (b.graph.global_cache_root.path) |global_cache| {
|
|
165
|
+
jw.objectField("global_cache_dir") catch @panic("OOM");
|
|
166
|
+
jw.write(global_cache) catch @panic("OOM");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
jw.objectField("dependencies") catch @panic("OOM");
|
|
170
|
+
jw.beginArray() catch @panic("OOM");
|
|
171
|
+
writeDeps(b, &jw) catch @panic("OOM");
|
|
172
|
+
jw.endArray() catch @panic("OOM");
|
|
173
|
+
jw.endObject() catch @panic("OOM");
|
|
174
|
+
|
|
175
|
+
const out = wf.add("sdistlist.json", wr.written());
|
|
176
|
+
const sdist_step = b.step("sdistlist", "generate a list of files for python sdist");
|
|
177
|
+
sdist_step.dependOn(&b.addInstallFile(out, "sdistlist.json").step);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
fn writeDeps(b: *std.Build, w: *std.json.Stringify) !void {
|
|
181
|
+
for (b.available_deps) |dep| {
|
|
182
|
+
try w.beginArray();
|
|
183
|
+
try w.write(dep[0]);
|
|
184
|
+
try w.write(dep[1]);
|
|
185
|
+
try w.endArray();
|
|
186
|
+
if (b.lazyDependency(dep[0], .{})) |lazy_dep| {
|
|
187
|
+
try writeDeps(lazy_dep.builder, w);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// compat for 0.16.0 and 0.17.0
|
|
193
|
+
pub fn findProgramCompat(b: *std.Build, names: []const []const u8) ?[]const u8 {
|
|
194
|
+
if (comptime (@import("builtin").zig_version.order(std.SemanticVersion.parse("0.16.0") catch unreachable) == .gt)) {
|
|
195
|
+
return b.findProgram(.{ .names = names });
|
|
196
|
+
}
|
|
197
|
+
return b.findProgram(names, &.{}) catch null;
|
|
198
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const Build = std.Build;
|
|
3
|
+
const LazyPath = Build.LazyPath;
|
|
4
|
+
const LowerDashStringFormatter = @import("LowerDashStringFormatter.zig");
|
|
5
|
+
|
|
6
|
+
const SDistStep = @This();
|
|
7
|
+
|
|
8
|
+
basename: []const u8,
|
|
9
|
+
builder: *Build.Step.Compile,
|
|
10
|
+
archive: LazyPath,
|
|
11
|
+
pub const Content = struct {
|
|
12
|
+
src: LazyPath,
|
|
13
|
+
dest: []const u8,
|
|
14
|
+
};
|
|
15
|
+
pub const Options = struct {
|
|
16
|
+
name: []const u8,
|
|
17
|
+
version: []const u8,
|
|
18
|
+
description: ?LazyPath = null,
|
|
19
|
+
files: []const Content = &.{},
|
|
20
|
+
build_args: []const []const u8 = &.{},
|
|
21
|
+
directories: []const Content = &.{},
|
|
22
|
+
sdist_builder: ?*Build.Step.Compile = null,
|
|
23
|
+
// the version of the ziglang python package to depend on.
|
|
24
|
+
zig_version: ?std.SemanticVersion = null,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
pub fn createInternal(b: *Build, options: Options) *SDistStep {
|
|
28
|
+
const self = b.allocator.create(SDistStep) catch @panic("OOM");
|
|
29
|
+
const basename = b.fmt("{f}-{s}.tar.gz", .{
|
|
30
|
+
LowerDashStringFormatter{ .str = options.name },
|
|
31
|
+
options.version,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const sdist_builder = options.sdist_builder orelse {
|
|
35
|
+
@panic("sdist_builder not set. use the top level .create() instead of .createInternal()!");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const run = b.addRunArtifact(sdist_builder);
|
|
39
|
+
run.addArg(b.fmt("--name={s}", .{options.name}));
|
|
40
|
+
run.addArg(b.fmt("--version={s}", .{options.version}));
|
|
41
|
+
if (options.description) |description| {
|
|
42
|
+
run.addPrefixedFileArg("--description=", description);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const zig_version = options.zig_version orelse @import("builtin").zig_version;
|
|
46
|
+
if (zig_version.build != null or zig_version.pre != null) {
|
|
47
|
+
std.log.warn("the python ziglang package is only published for releases.", .{});
|
|
48
|
+
std.log.warn("the resulting sdist might not be installable!", .{});
|
|
49
|
+
std.log.warn("set .zig_version for your sdist to a release explicitly", .{});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
run.addArg(b.fmt("--zig-version={f}", .{zig_version}));
|
|
53
|
+
|
|
54
|
+
const archive = run.addPrefixedOutputFileArg("--output=", basename);
|
|
55
|
+
for (options.files) |content| {
|
|
56
|
+
run.addPrefixedFileArg("--file=", content.src);
|
|
57
|
+
run.addArg(content.dest);
|
|
58
|
+
}
|
|
59
|
+
for (options.directories) |content| {
|
|
60
|
+
run.addPrefixedDirectoryArg("--dir=", content.src);
|
|
61
|
+
run.addArg(content.dest);
|
|
62
|
+
}
|
|
63
|
+
for (options.build_args) |ba| {
|
|
64
|
+
run.addArg(b.fmt("--build={s}", .{ba}));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
self.* = .{
|
|
68
|
+
.basename = basename,
|
|
69
|
+
.builder = sdist_builder,
|
|
70
|
+
.archive = archive,
|
|
71
|
+
};
|
|
72
|
+
return self;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
pub fn getEmittedArchive(self: *SDistStep) LazyPath {
|
|
76
|
+
return self.archive;
|
|
77
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
3
|
+
const Build = std.Build;
|
|
4
|
+
const LazyPath = Build.LazyPath;
|
|
5
|
+
const CPython = @import("CPython.zig");
|
|
6
|
+
|
|
7
|
+
const VenvInstallTest = @This();
|
|
8
|
+
|
|
9
|
+
venv: *Build.Step.WriteFile,
|
|
10
|
+
step: *Build.Step,
|
|
11
|
+
install_run: *Build.Step.Run,
|
|
12
|
+
pub const Options = struct {
|
|
13
|
+
sdist: LazyPath,
|
|
14
|
+
test_py: ?LazyPath = null,
|
|
15
|
+
// keeps intermediate pip directories. use for debugging installation
|
|
16
|
+
no_clean: bool,
|
|
17
|
+
// pass in python interpreter. uses system python if null
|
|
18
|
+
python: ?LazyPath = null,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
pub fn create(b: *Build, options: Options) *VenvInstallTest {
|
|
22
|
+
const self = b.allocator.create(VenvInstallTest) catch @panic("OOM");
|
|
23
|
+
|
|
24
|
+
const wf = b.addWriteFiles();
|
|
25
|
+
wf.mode = .tmp;
|
|
26
|
+
self.venv = wf;
|
|
27
|
+
|
|
28
|
+
const venv_run = std.Build.Step.Run.create(b, "venv");
|
|
29
|
+
if (options.python) |python| {
|
|
30
|
+
venv_run.addFileArg(python);
|
|
31
|
+
} else {
|
|
32
|
+
if (CPython.findProgramCompat(b, &.{ "python", "python3" })) |python| {
|
|
33
|
+
venv_run.addArg(python);
|
|
34
|
+
} else {
|
|
35
|
+
venv_run.step.dependOn(&b.addFail("system python not found").step);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
venv_run.addArgs(&.{ "-m", "venv" });
|
|
39
|
+
venv_run.addDirectoryArg(wf.getDirectory());
|
|
40
|
+
const venv_python = if (builtin.target.os.tag == .windows)
|
|
41
|
+
wf.getDirectory().path(b, "Scripts/python")
|
|
42
|
+
else
|
|
43
|
+
wf.getDirectory().path(b, "bin/python");
|
|
44
|
+
|
|
45
|
+
const deps_run = std.Build.Step.Run.create(b, "venv");
|
|
46
|
+
deps_run.addFileArg(venv_python);
|
|
47
|
+
deps_run.addArgs(&.{
|
|
48
|
+
"-m",
|
|
49
|
+
"pip",
|
|
50
|
+
"install",
|
|
51
|
+
"-U",
|
|
52
|
+
"pip",
|
|
53
|
+
"wheel",
|
|
54
|
+
});
|
|
55
|
+
deps_run.step.dependOn(&venv_run.step);
|
|
56
|
+
|
|
57
|
+
self.install_run = std.Build.Step.Run.create(b, "venv");
|
|
58
|
+
self.step = &self.install_run.step;
|
|
59
|
+
|
|
60
|
+
self.install_run.addFileArg(venv_python);
|
|
61
|
+
self.install_run.addArgs(&.{ "-m", "pip", "install", "--force-reinstall", "--verbose" });
|
|
62
|
+
if (options.no_clean) self.install_run.addArg("--no-clean");
|
|
63
|
+
|
|
64
|
+
self.install_run.step.dependOn(&deps_run.step);
|
|
65
|
+
self.install_run.addFileArg(options.sdist);
|
|
66
|
+
|
|
67
|
+
if (options.test_py) |test_py| {
|
|
68
|
+
const test_py_step = std.Build.Step.Run.create(b, "venv");
|
|
69
|
+
test_py_step.addFileArg(venv_python);
|
|
70
|
+
test_py_step.addFileArg(test_py);
|
|
71
|
+
self.step = &test_py_step.step;
|
|
72
|
+
test_py_step.step.dependOn(&self.install_run.step);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return self;
|
|
76
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sysconfig
|
|
4
|
+
import sys
|
|
5
|
+
import shutil
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
output_dir = sys.argv[1]
|
|
9
|
+
syspath = sysconfig.get_paths()
|
|
10
|
+
|
|
11
|
+
lib_filename = 'python{}{}.lib'.format(
|
|
12
|
+
sys.version_info.major, sys.version_info.minor)
|
|
13
|
+
|
|
14
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
15
|
+
shutil.copytree(syspath['include'], output_dir, dirs_exist_ok=True)
|
|
16
|
+
|
|
17
|
+
found_lib = False
|
|
18
|
+
sources = [syspath['include']]
|
|
19
|
+
|
|
20
|
+
for k, v in sysconfig.get_config_vars().items():
|
|
21
|
+
if not isinstance(v, str):
|
|
22
|
+
continue
|
|
23
|
+
vf = os.path.join(v, lib_filename)
|
|
24
|
+
if os.path.exists(vf):
|
|
25
|
+
try:
|
|
26
|
+
shutil.copyfile(vf, os.path.join(output_dir, 'python.lib'))
|
|
27
|
+
found_lib = True
|
|
28
|
+
sources.append(vf)
|
|
29
|
+
break
|
|
30
|
+
except:
|
|
31
|
+
pass
|
|
32
|
+
else:
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
vfl = os.path.join(v, 'libs', lib_filename)
|
|
36
|
+
if os.path.exists(vfl):
|
|
37
|
+
try:
|
|
38
|
+
shutil.copyfile(vfl, os.path.join(output_dir, 'python.lib'))
|
|
39
|
+
found_lib = True
|
|
40
|
+
sources.append(vfl)
|
|
41
|
+
break
|
|
42
|
+
except:
|
|
43
|
+
pass
|
|
44
|
+
else:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
if sys.platform == 'windows' and not found_lib:
|
|
48
|
+
print("Warning: Did not find", lib_filename, "in:", file=sys.stderr)
|
|
49
|
+
print(lib_paths, file=sys.stderr)
|
|
50
|
+
|
|
51
|
+
python_h = os.path.join(output_dir, 'Python.h')
|
|
52
|
+
if not os.path.isfile(python_h):
|
|
53
|
+
raise Exception("Python.h missing! syspath include: {}\n output: {}".format(
|
|
54
|
+
syspath['include'], output_dir))
|
|
55
|
+
|
|
56
|
+
output_header = os.path.join(output_dir, 'Zig_Python_With_Hexver.h')
|
|
57
|
+
|
|
58
|
+
with open(output_header, 'w') as fd:
|
|
59
|
+
fd.write('''
|
|
60
|
+
// Zig_Python_With_Hexver.h generated by extract_link_info.py
|
|
61
|
+
// sources: {}
|
|
62
|
+
#ifndef PY_SSIZE_T_CLEAN
|
|
63
|
+
#define PY_SSIZE_T_CLEAN
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#ifndef PYHEXVER
|
|
67
|
+
#define PYHEXVER {}
|
|
68
|
+
#endif
|
|
69
|
+
|
|
70
|
+
#include "Python.h"
|
|
71
|
+
'''.format(sources, sys.hexversion))
|
|
72
|
+
print('OK:', output_header)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
3
|
+
pub const c = @import("c");
|
|
4
|
+
pub const version = @embedFile("version");
|
|
5
|
+
|
|
6
|
+
pub fn addVersion(mod: [*c]c.PyObject) void {
|
|
7
|
+
const semver = comptime std.SemanticVersion.parse(version) catch {
|
|
8
|
+
@compileLog("could not parse version:");
|
|
9
|
+
@compileError(version);
|
|
10
|
+
};
|
|
11
|
+
const version_dict = c.PyDict_New();
|
|
12
|
+
|
|
13
|
+
_ = c.PyDict_SetItemString(version_dict, "major", c.Py_BuildValue("n", semver.major));
|
|
14
|
+
_ = c.PyDict_SetItemString(version_dict, "minor", c.Py_BuildValue("n", semver.minor));
|
|
15
|
+
_ = c.PyDict_SetItemString(version_dict, "patch", c.Py_BuildValue("n", semver.patch));
|
|
16
|
+
if (semver.pre) |pre| {
|
|
17
|
+
_ = c.PyDict_SetItemString(version_dict, "pre", c.Py_BuildValue("s#", pre.ptr, pre.len));
|
|
18
|
+
} else {
|
|
19
|
+
_ = c.PyDict_SetItemString(version_dict, "pre", c.Py_BuildValue(""));
|
|
20
|
+
}
|
|
21
|
+
if (semver.build) |build| {
|
|
22
|
+
_ = c.PyDict_SetItemString(version_dict, "build", c.Py_BuildValue("s#", build.ptr, build.len));
|
|
23
|
+
} else {
|
|
24
|
+
_ = c.PyDict_SetItemString(version_dict, "build", c.Py_BuildValue(""));
|
|
25
|
+
}
|
|
26
|
+
_ = c.PyObject_SetAttrString(
|
|
27
|
+
mod,
|
|
28
|
+
"__version__",
|
|
29
|
+
version_dict,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const version_str = c.Py_BuildValue("s#", version.ptr, version.len);
|
|
33
|
+
_ = c.PyObject_SetAttrString(
|
|
34
|
+
mod,
|
|
35
|
+
"__version_str__",
|
|
36
|
+
version_str,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub fn addZigTargetTriple(mod: [*c]c.PyObject) void {
|
|
41
|
+
var arena_instance = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
|
42
|
+
defer arena_instance.deinit();
|
|
43
|
+
const target_triple = builtin.target.zigTriple(arena_instance.allocator()) catch @panic("OOM");
|
|
44
|
+
const target_triple_str = c.Py_BuildValue("s#", target_triple.ptr, target_triple.len);
|
|
45
|
+
_ = c.PyObject_SetAttrString(
|
|
46
|
+
mod,
|
|
47
|
+
"__zig_target_triple__",
|
|
48
|
+
target_triple_str,
|
|
49
|
+
);
|
|
50
|
+
}
|
zig_zon-0.1.3/MANIFEST.in
DELETED
zig_zon-0.1.3/PKG-INFO
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: zig-zon
|
|
3
|
-
Version: 0.1.3
|
|
4
|
-
Summary: a native cpython extension to parse zig object notation strings
|
|
5
|
-
Author-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
6
|
-
Maintainer-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
7
|
-
License-Expression: MIT
|
|
8
|
-
Project-URL: Homepage, https://codeberg.org/dasimmet/python-zig-zon
|
|
9
|
-
Project-URL: Issues, https://codeberg.org/dasimmet/python-zig-zon/issues
|
|
10
|
-
Keywords: zig,ziglang,zon,cpython
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Requires-Python: >=3.9
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
|
|
20
|
-
# Python Zig Zon Parser
|
|
21
|
-
|
|
22
|
-
A native python extension built with zig to parse zig-object-notation strings
|
|
23
|
-
into python objects.
|
|
24
|
-
|
|
25
|
-
On PyPi it is only distributed in source, and built during install.
|
|
26
|
-
It therefore needs to download the `ziglang` python package.
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
install from source on pypi:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pip install zig-zon
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
running:
|
|
37
|
-
|
|
38
|
-
```python
|
|
39
|
-
import zig_zon
|
|
40
|
-
parsed = zig_zon.parse('.{.allyourcode = .are_belong_to_us, .asd = 123}')
|
|
41
|
-
print(parsed)
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
or, look at the [test file](https://codeberg.org/dasimmet/python-zig-zon/src/branch/main/src/test_zig_zon.py)
|
|
45
|
-
|
|
46
|
-
## How it works
|
|
47
|
-
|
|
48
|
-
When you run pip install, the source distribution is downloaded, and since
|
|
49
|
-
this package depends on the `ziglang` as well as my setuptools helper package:
|
|
50
|
-
[setuptools-zig-build](https://codeberg.org/dasimmet/setuptools-zig-build)
|
|
51
|
-
|
|
52
|
-
to execute `zig build` and put the resulting library in the wheel.
|
|
53
|
-
|
|
54
|
-
## Developing
|
|
55
|
-
|
|
56
|
-
as opposed to other solutions for building cpython extensions in zig,
|
|
57
|
-
i want to develop this using:
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
zig build test --watch
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
for linking against the local python installation [setuptools-zig-build](https://codeberg.org/dasimmet/setuptools-zig-build)
|
|
64
|
-
runs a python script that imports the cpython headers into zig's build cache.
|
|
65
|
-
When the module is built using `pip`, zig will get a `-Dpython=` option pointing to the correct python executable,
|
|
66
|
-
otherwise system python in `PATH` is used.
|
|
67
|
-
pip installation also uses a `-Dversion=` option for the pip package version.
|
zig_zon-0.1.3/README.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Python Zig Zon Parser
|
|
2
|
-
|
|
3
|
-
A native python extension built with zig to parse zig-object-notation strings
|
|
4
|
-
into python objects.
|
|
5
|
-
|
|
6
|
-
On PyPi it is only distributed in source, and built during install.
|
|
7
|
-
It therefore needs to download the `ziglang` python package.
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
install from source on pypi:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pip install zig-zon
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
running:
|
|
18
|
-
|
|
19
|
-
```python
|
|
20
|
-
import zig_zon
|
|
21
|
-
parsed = zig_zon.parse('.{.allyourcode = .are_belong_to_us, .asd = 123}')
|
|
22
|
-
print(parsed)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
or, look at the [test file](https://codeberg.org/dasimmet/python-zig-zon/src/branch/main/src/test_zig_zon.py)
|
|
26
|
-
|
|
27
|
-
## How it works
|
|
28
|
-
|
|
29
|
-
When you run pip install, the source distribution is downloaded, and since
|
|
30
|
-
this package depends on the `ziglang` as well as my setuptools helper package:
|
|
31
|
-
[setuptools-zig-build](https://codeberg.org/dasimmet/setuptools-zig-build)
|
|
32
|
-
|
|
33
|
-
to execute `zig build` and put the resulting library in the wheel.
|
|
34
|
-
|
|
35
|
-
## Developing
|
|
36
|
-
|
|
37
|
-
as opposed to other solutions for building cpython extensions in zig,
|
|
38
|
-
i want to develop this using:
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
zig build test --watch
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
for linking against the local python installation [setuptools-zig-build](https://codeberg.org/dasimmet/setuptools-zig-build)
|
|
45
|
-
runs a python script that imports the cpython headers into zig's build cache.
|
|
46
|
-
When the module is built using `pip`, zig will get a `-Dpython=` option pointing to the correct python executable,
|
|
47
|
-
otherwise system python in `PATH` is used.
|
|
48
|
-
pip installation also uses a `-Dversion=` option for the pip package version.
|
zig_zon-0.1.3/build.zig
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const std = @import("std");
|
|
2
|
-
const Build = std.Build;
|
|
3
|
-
|
|
4
|
-
const CPython = @import("setuptools_zig_build").CPython;
|
|
5
|
-
|
|
6
|
-
pub fn build(b: *Build) void {
|
|
7
|
-
const target = b.standardTargetOptions(.{});
|
|
8
|
-
const optimize = b.standardOptimizeOption(.{});
|
|
9
|
-
const python = CPython.findAddOption(b);
|
|
10
|
-
python.addVersionOption(b, @import("build.zig.zon").version);
|
|
11
|
-
|
|
12
|
-
CPython.addSdistList(b);
|
|
13
|
-
|
|
14
|
-
const lib = b.addLibrary(.{
|
|
15
|
-
.name = "zig_zon",
|
|
16
|
-
.root_module = b.addModule("zig_zon", .{
|
|
17
|
-
.root_source_file = b.path("src/zig_zon.zig"),
|
|
18
|
-
.target = target,
|
|
19
|
-
.optimize = optimize,
|
|
20
|
-
}),
|
|
21
|
-
.linkage = .dynamic,
|
|
22
|
-
.use_llvm = true,
|
|
23
|
-
});
|
|
24
|
-
CPython.installExtLib(b, lib);
|
|
25
|
-
|
|
26
|
-
python.link(b, .{
|
|
27
|
-
.lib = lib,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const install_test = b.addInstallFile(b.path("src/test_zig_zon.py"), "lib/test_zig_zon.py");
|
|
31
|
-
b.step("install-test", "install the python test script alongside the built modules").dependOn(&install_test.step);
|
|
32
|
-
|
|
33
|
-
const run_test = python.run_test(b, lib, b.path("src/test_zig_zon.py"));
|
|
34
|
-
|
|
35
|
-
b.step("test", "run the python test script").dependOn(&run_test.step);
|
|
36
|
-
}
|
zig_zon-0.1.3/pyproject.toml
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "zig-zon"
|
|
3
|
-
authors = [{ name = "Tobias Simetsreiter", email = "dasimmet@gmail.com" }]
|
|
4
|
-
maintainers = [{ name = "Tobias Simetsreiter", email = "dasimmet@gmail.com" }]
|
|
5
|
-
description = "a native cpython extension to parse zig object notation strings"
|
|
6
|
-
readme = "README.md"
|
|
7
|
-
requires-python = ">=3.9"
|
|
8
|
-
dynamic = ["version"]
|
|
9
|
-
license = "MIT"
|
|
10
|
-
license-files = ["LICENSE"]
|
|
11
|
-
keywords = ["zig", "ziglang", "zon", "cpython"]
|
|
12
|
-
classifiers = [
|
|
13
|
-
"Development Status :: 4 - Beta",
|
|
14
|
-
"Intended Audience :: Developers",
|
|
15
|
-
"Programming Language :: Python :: 3",
|
|
16
|
-
"Programming Language :: Python :: 3.9",
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
[project.urls]
|
|
20
|
-
Homepage = "https://codeberg.org/dasimmet/python-zig-zon"
|
|
21
|
-
Issues = "https://codeberg.org/dasimmet/python-zig-zon/issues"
|
|
22
|
-
|
|
23
|
-
[build-system]
|
|
24
|
-
requires = [
|
|
25
|
-
"setuptools",
|
|
26
|
-
"setuptools-scm",
|
|
27
|
-
"ziglang==0.16.0",
|
|
28
|
-
"setuptools-zig-build==0.3.1",
|
|
29
|
-
]
|
|
30
|
-
build-backend = "setuptools.build_meta"
|
|
31
|
-
|
|
32
|
-
[tool.setuptools_scm]
|
zig_zon-0.1.3/sdistlist.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"global_cache_dir":"/home/tobi/.cache/zig","dependencies":[["setuptools_zig_build","setuptools_zig_build-0.3.1-Ep6e3IE1AAAa8gtHLvqZUBeVJuKe0iB_eyutka4cw_EP"]]}
|
zig_zon-0.1.3/setup.cfg
DELETED
zig_zon-0.1.3/setup.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from setuptools import Extension
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
setup(
|
|
5
|
-
name='zig-zon',
|
|
6
|
-
packages=[],
|
|
7
|
-
zig_build={
|
|
8
|
-
# stores zig's depdendencies in python's sdist. requires a call to
|
|
9
|
-
# CPython.addSdistList(b); in `build.zig`
|
|
10
|
-
"sdist": True,
|
|
11
|
-
# tries to import 'ziglang' to get a zig compiler when building wheel
|
|
12
|
-
"use_ziglang_python_package": True,
|
|
13
|
-
# passes -Doptimize= to zig build
|
|
14
|
-
"optimize": "ReleaseSmall",
|
|
15
|
-
# passes -Dversion=<pip package version> to zig build
|
|
16
|
-
"pass_version_option": True,
|
|
17
|
-
# extra arguments to zig build
|
|
18
|
-
'extra_args': [
|
|
19
|
-
"install", "test",
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
ext_modules=[Extension('zig_zon', [])],
|
|
23
|
-
)
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
from pprint import pprint
|
|
4
|
-
|
|
5
|
-
import zig_zon
|
|
6
|
-
print('zig_zon module:', zig_zon)
|
|
7
|
-
|
|
8
|
-
teststr = """
|
|
9
|
-
.{
|
|
10
|
-
.asdf = "ccc",
|
|
11
|
-
.my_bool = true,
|
|
12
|
-
.my_float = 1.23,
|
|
13
|
-
.my_hex_int = 0xdeadbeef,
|
|
14
|
-
.my_negative_int = -432_123_111,
|
|
15
|
-
.my_negative_big_int = -4611686018427387904,
|
|
16
|
-
.my_optional = null,
|
|
17
|
-
}"""
|
|
18
|
-
|
|
19
|
-
testzon = zig_zon.parse(teststr)
|
|
20
|
-
print('teststr:')
|
|
21
|
-
pprint(testzon)
|
|
22
|
-
pprint(zig_zon.__version__)
|
|
23
|
-
pprint(zig_zon.__version_str__)
|
|
24
|
-
|
|
25
|
-
assert testzon['asdf'] == "ccc"
|
|
26
|
-
assert testzon['my_float'] == 1.23
|
|
27
|
-
assert testzon['my_hex_int'] == 0xdeadbeef
|
|
28
|
-
assert testzon['my_negative_int'] == -432_123_111
|
|
29
|
-
assert testzon['my_negative_big_int'] == -4611686018427387904
|
|
30
|
-
assert testzon['my_optional'] == None
|
|
31
|
-
assert zig_zon.parse(str(2**63 - 1)) == 2**63 - 1
|
|
32
|
-
assert zig_zon.parse(str(2**63)) == 2**63
|
|
33
|
-
assert zig_zon.parse(str(2**64 - 1)) == 2**64 - 1
|
|
34
|
-
|
|
35
|
-
# print("TODO: 2**64 ==", 2**64, ", zig_zon.parse(str(2**64)) ==",
|
|
36
|
-
# zig_zon.parse(str(2**64)))
|
|
37
|
-
# assert zig_zon.parse(str(2**64)) == str(2**64)
|
|
38
|
-
|
|
39
|
-
print('build.zig.zon:')
|
|
40
|
-
with open('build.zig.zon') as fd:
|
|
41
|
-
pprint(zig_zon.parse(fd.read()))
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: zig-zon
|
|
3
|
-
Version: 0.1.3
|
|
4
|
-
Summary: a native cpython extension to parse zig object notation strings
|
|
5
|
-
Author-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
6
|
-
Maintainer-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
7
|
-
License-Expression: MIT
|
|
8
|
-
Project-URL: Homepage, https://codeberg.org/dasimmet/python-zig-zon
|
|
9
|
-
Project-URL: Issues, https://codeberg.org/dasimmet/python-zig-zon/issues
|
|
10
|
-
Keywords: zig,ziglang,zon,cpython
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Requires-Python: >=3.9
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
|
|
20
|
-
# Python Zig Zon Parser
|
|
21
|
-
|
|
22
|
-
A native python extension built with zig to parse zig-object-notation strings
|
|
23
|
-
into python objects.
|
|
24
|
-
|
|
25
|
-
On PyPi it is only distributed in source, and built during install.
|
|
26
|
-
It therefore needs to download the `ziglang` python package.
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
install from source on pypi:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pip install zig-zon
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
running:
|
|
37
|
-
|
|
38
|
-
```python
|
|
39
|
-
import zig_zon
|
|
40
|
-
parsed = zig_zon.parse('.{.allyourcode = .are_belong_to_us, .asd = 123}')
|
|
41
|
-
print(parsed)
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
or, look at the [test file](https://codeberg.org/dasimmet/python-zig-zon/src/branch/main/src/test_zig_zon.py)
|
|
45
|
-
|
|
46
|
-
## How it works
|
|
47
|
-
|
|
48
|
-
When you run pip install, the source distribution is downloaded, and since
|
|
49
|
-
this package depends on the `ziglang` as well as my setuptools helper package:
|
|
50
|
-
[setuptools-zig-build](https://codeberg.org/dasimmet/setuptools-zig-build)
|
|
51
|
-
|
|
52
|
-
to execute `zig build` and put the resulting library in the wheel.
|
|
53
|
-
|
|
54
|
-
## Developing
|
|
55
|
-
|
|
56
|
-
as opposed to other solutions for building cpython extensions in zig,
|
|
57
|
-
i want to develop this using:
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
zig build test --watch
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
for linking against the local python installation [setuptools-zig-build](https://codeberg.org/dasimmet/setuptools-zig-build)
|
|
64
|
-
runs a python script that imports the cpython headers into zig's build cache.
|
|
65
|
-
When the module is built using `pip`, zig will get a `-Dpython=` option pointing to the correct python executable,
|
|
66
|
-
otherwise system python in `PATH` is used.
|
|
67
|
-
pip installation also uses a `-Dversion=` option for the pip package version.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
MANIFEST.in
|
|
3
|
-
README.md
|
|
4
|
-
build.zig
|
|
5
|
-
build.zig.zon
|
|
6
|
-
pyproject.toml
|
|
7
|
-
setup.py
|
|
8
|
-
src/test_zig_zon.py
|
|
9
|
-
src/zig_zon.zig
|
|
10
|
-
zig_zon.egg-info/PKG-INFO
|
|
11
|
-
zig_zon.egg-info/SOURCES.txt
|
|
12
|
-
zig_zon.egg-info/dependency_links.txt
|
|
13
|
-
zig_zon.egg-info/top_level.txt
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
zig_zon
|
|
File without changes
|