aether-dsc 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.
- aether_dsc-0.2.0/LICENSE +202 -0
- aether_dsc-0.2.0/NOTICE +2 -0
- aether_dsc-0.2.0/PKG-INFO +60 -0
- aether_dsc-0.2.0/README.md +41 -0
- aether_dsc-0.2.0/aether_dsc/__init__.py +99 -0
- aether_dsc-0.2.0/aether_dsc/_core.py +200 -0
- aether_dsc-0.2.0/aether_dsc/_payload/a9c89146169d59183c41dba2a050a420a5f3dd40729154ae547b61a2239c38b8.bin +0 -0
- aether_dsc-0.2.0/aether_dsc/_rtc_check.py +254 -0
- aether_dsc-0.2.0/aether_dsc/_seal_impl.py +175 -0
- aether_dsc-0.2.0/aether_dsc/payload_headers.txt +69 -0
- aether_dsc-0.2.0/aether_dsc/payload_headers_host.txt +32 -0
- aether_dsc-0.2.0/aether_dsc/seal.py +47 -0
- aether_dsc-0.2.0/aether_dsc.egg-info/PKG-INFO +60 -0
- aether_dsc-0.2.0/aether_dsc.egg-info/SOURCES.txt +18 -0
- aether_dsc-0.2.0/aether_dsc.egg-info/dependency_links.txt +1 -0
- aether_dsc-0.2.0/aether_dsc.egg-info/requires.txt +3 -0
- aether_dsc-0.2.0/aether_dsc.egg-info/top_level.txt +1 -0
- aether_dsc-0.2.0/pyproject.toml +77 -0
- aether_dsc-0.2.0/setup.cfg +4 -0
- aether_dsc-0.2.0/tests/test_aether_dsc.py +395 -0
aether_dsc-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
aether_dsc-0.2.0/NOTICE
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aether-dsc
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: aether-dsc — the sealed AETHER header payload: opaque, digest-named, no readable source in the wheel
|
|
5
|
+
Author: Alessandro Masat
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/amasat01/aether
|
|
8
|
+
Project-URL: Documentation, https://amasat01.github.io/aether/
|
|
9
|
+
Project-URL: Repository, https://github.com/amasat01/aether
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
License-File: NOTICE
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest; extra == "test"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# aether-dsc
|
|
21
|
+
|
|
22
|
+
The sealed AETHER header payload.
|
|
23
|
+
|
|
24
|
+
## What the payload is
|
|
25
|
+
|
|
26
|
+
aether ships to Python-only users as ONE opaque, digest-named blob instead of
|
|
27
|
+
readable headers inside a wheel's include tree. `aether_dsc.payload()`
|
|
28
|
+
returns a `Payload(digest, headers)`: `digest` is a sha256 over the sorted
|
|
29
|
+
`(name, bytes)` pairs of `headers`; `headers` maps include-relative names
|
|
30
|
+
(`aether/...`, `rtc/<std name>`, `plugin/gref_layout.h`, `plugin/gref_abi.h`)
|
|
31
|
+
to bytes — the exact set an NVRTC-compiled HAWK device kernel needs, plus
|
|
32
|
+
what a host compiler needs through `Payload.serve()`.
|
|
33
|
+
|
|
34
|
+
Two consumers: **device** — NVRTC compiles a kernel straight from
|
|
35
|
+
`payload().headers`, in memory, nothing written to disk; **host, or any
|
|
36
|
+
file-only compiler** — `payload().serve()` is a context manager materialising
|
|
37
|
+
the headers into a private, owner-only (`0700`) RAM directory (`/dev/shm`
|
|
38
|
+
when it is a tmpfs, else `$TMPDIR`), removed on both the normal exit path
|
|
39
|
+
AND a `with`-block exception.
|
|
40
|
+
|
|
41
|
+
## How to seal one
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m aether_dsc.seal
|
|
45
|
+
```
|
|
46
|
+
Reads this checkout's aether headers — scoped to the committed manifest
|
|
47
|
+
`aether_dsc/payload_headers.txt` (package data, not every file under
|
|
48
|
+
`aether/` — see that file's comment for why) — the seven `rtc/` shims, and
|
|
49
|
+
the sibling `eagle` checkout's `plugin/gref_layout.h` + `plugin/gref_abi.h`
|
|
50
|
+
(host path only — NVRTC gets an alias to the layout header's bytes instead);
|
|
51
|
+
runs the NVRTC-clean gate (every device-reachable header compiles under
|
|
52
|
+
NVRTC with zero diagnostics); only then writes
|
|
53
|
+
`aether_dsc/_payload/<digest>.bin` — a payload failing the gate is
|
|
54
|
+
refused, never shipped silently broken.
|
|
55
|
+
|
|
56
|
+
## Opacity, not secrecy
|
|
57
|
+
|
|
58
|
+
The blob is a zlib-compressed tar — not obfuscation against a determined
|
|
59
|
+
reader, just enough that `strings`/`cat` on the wheel does not hand back
|
|
60
|
+
readable C++ source.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# aether-dsc
|
|
2
|
+
|
|
3
|
+
The sealed AETHER header payload.
|
|
4
|
+
|
|
5
|
+
## What the payload is
|
|
6
|
+
|
|
7
|
+
aether ships to Python-only users as ONE opaque, digest-named blob instead of
|
|
8
|
+
readable headers inside a wheel's include tree. `aether_dsc.payload()`
|
|
9
|
+
returns a `Payload(digest, headers)`: `digest` is a sha256 over the sorted
|
|
10
|
+
`(name, bytes)` pairs of `headers`; `headers` maps include-relative names
|
|
11
|
+
(`aether/...`, `rtc/<std name>`, `plugin/gref_layout.h`, `plugin/gref_abi.h`)
|
|
12
|
+
to bytes — the exact set an NVRTC-compiled HAWK device kernel needs, plus
|
|
13
|
+
what a host compiler needs through `Payload.serve()`.
|
|
14
|
+
|
|
15
|
+
Two consumers: **device** — NVRTC compiles a kernel straight from
|
|
16
|
+
`payload().headers`, in memory, nothing written to disk; **host, or any
|
|
17
|
+
file-only compiler** — `payload().serve()` is a context manager materialising
|
|
18
|
+
the headers into a private, owner-only (`0700`) RAM directory (`/dev/shm`
|
|
19
|
+
when it is a tmpfs, else `$TMPDIR`), removed on both the normal exit path
|
|
20
|
+
AND a `with`-block exception.
|
|
21
|
+
|
|
22
|
+
## How to seal one
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python -m aether_dsc.seal
|
|
26
|
+
```
|
|
27
|
+
Reads this checkout's aether headers — scoped to the committed manifest
|
|
28
|
+
`aether_dsc/payload_headers.txt` (package data, not every file under
|
|
29
|
+
`aether/` — see that file's comment for why) — the seven `rtc/` shims, and
|
|
30
|
+
the sibling `eagle` checkout's `plugin/gref_layout.h` + `plugin/gref_abi.h`
|
|
31
|
+
(host path only — NVRTC gets an alias to the layout header's bytes instead);
|
|
32
|
+
runs the NVRTC-clean gate (every device-reachable header compiles under
|
|
33
|
+
NVRTC with zero diagnostics); only then writes
|
|
34
|
+
`aether_dsc/_payload/<digest>.bin` — a payload failing the gate is
|
|
35
|
+
refused, never shipped silently broken.
|
|
36
|
+
|
|
37
|
+
## Opacity, not secrecy
|
|
38
|
+
|
|
39
|
+
The blob is a zlib-compressed tar — not obfuscation against a determined
|
|
40
|
+
reader, just enough that `strings`/`cat` on the wheel does not hand back
|
|
41
|
+
readable C++ source.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright 2026 Alessandro Masat
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""aether-dsc — the sealed AETHER header payload.
|
|
5
|
+
|
|
6
|
+
aether ships to Python-only users as a SEALED PAYLOAD, never as readable
|
|
7
|
+
headers inside a wheel's include tree: one digest-named, zlib-compressed tar
|
|
8
|
+
blob (opacity, not secrecy — see :mod:`aether_dsc._core`) carrying the
|
|
9
|
+
`aether/`/`rtc/` headers a HAWK-emitted device kernel needs, plus eagle's
|
|
10
|
+
`plugin/gref_layout.h` (device-clean) and `plugin/gref_abi.h` (host-only —
|
|
11
|
+
NVRTC never sees its real bytes; :mod:`hawk.compile.nvrtc` serves an alias to
|
|
12
|
+
the layout header's instead). Two consumers:
|
|
13
|
+
|
|
14
|
+
* **device** — NVRTC compiles a kernel straight from :func:`payload`'s
|
|
15
|
+
in-memory `headers` mapping; nothing touches disk.
|
|
16
|
+
* **host, or any file-only compiler** — :meth:`Payload.serve` materialises
|
|
17
|
+
the payload into a private, owner-only RAM directory for the compile's
|
|
18
|
+
lifetime and removes it afterwards, failure path included.
|
|
19
|
+
|
|
20
|
+
Typical use::
|
|
21
|
+
|
|
22
|
+
import aether_dsc
|
|
23
|
+
p = aether_dsc.payload() # the blob shipped in this wheel
|
|
24
|
+
# device: hand p.digest / p.headers to NVRTC (hawk.compile.nvrtc)
|
|
25
|
+
with p.serve() as include_root: # host / any file compiler
|
|
26
|
+
... # -I include_root
|
|
27
|
+
|
|
28
|
+
Building a payload from a live checkout (never the shipped-wheel path — a
|
|
29
|
+
developer's own aether tree, or the CLI that regenerates the shipped blob)
|
|
30
|
+
goes through :func:`seal`; see :mod:`aether_dsc.seal`'s module docstring.
|
|
31
|
+
"""
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
from ._core import Payload, PAYLOAD_DIR, _unpack, digest_of
|
|
35
|
+
# Imported from `_seal_impl`, deliberately NOT from `.seal`:
|
|
36
|
+
# `aether_dsc/seal.py` is `python -m aether_dsc.seal`'s CLI file, and
|
|
37
|
+
# Python binds `aether_dsc.seal` to that MODULE the instant anything imports
|
|
38
|
+
# it — which running the CLI does internally. Importing the function from
|
|
39
|
+
# its own home (`_seal_impl.py`) instead means `aether_dsc.seal` stays
|
|
40
|
+
# callable even in a process that has also run the CLI or imported
|
|
41
|
+
# `aether_dsc.seal` as a submodule (see `_seal_impl`'s docstring;
|
|
42
|
+
# `tests/test_aether_dsc.py` exercises both in one process).
|
|
43
|
+
from ._seal_impl import seal
|
|
44
|
+
|
|
45
|
+
__all__ = ["Payload", "seal", "payload", "version", "PAYLOAD_DIR"]
|
|
46
|
+
|
|
47
|
+
#: This distribution's version — tracks aether's own (`aether/version.h`:
|
|
48
|
+
#: `constexpr version()`), because a sealed payload speaks for exactly one
|
|
49
|
+
#: aether checkout and a version skew between the two would silently claim
|
|
50
|
+
#: otherwise.
|
|
51
|
+
version = "0.2.0"
|
|
52
|
+
|
|
53
|
+
_PAYLOAD_CACHE: Payload | None = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def payload() -> Payload:
|
|
57
|
+
"""The sealed blob shipped in this distribution — decompressed
|
|
58
|
+
once per process and cached; every call after the first returns the same
|
|
59
|
+
object.
|
|
60
|
+
|
|
61
|
+
Raises `FileNotFoundError` when this checkout carries no blob yet (a
|
|
62
|
+
source tree that has never run ``python -m aether_dsc.seal``, or an
|
|
63
|
+
editable install before the first seal). Nothing here falls back to
|
|
64
|
+
sealing the live tree — that fallback belongs to
|
|
65
|
+
``hawk.compile.payload.current_payload()``, gated on
|
|
66
|
+
`$HAWK_AETHER_INCLUDE`: a caller that wants "seal if there is no
|
|
67
|
+
blob" asks for it explicitly, `payload()` never guesses.
|
|
68
|
+
"""
|
|
69
|
+
global _PAYLOAD_CACHE
|
|
70
|
+
if _PAYLOAD_CACHE is not None:
|
|
71
|
+
return _PAYLOAD_CACHE
|
|
72
|
+
blobs = sorted(PAYLOAD_DIR.glob("*.bin")) if PAYLOAD_DIR.is_dir() else []
|
|
73
|
+
if not blobs:
|
|
74
|
+
raise FileNotFoundError(
|
|
75
|
+
f"no sealed payload under {PAYLOAD_DIR} — run `python -m "
|
|
76
|
+
"aether_dsc.seal` from the aether/dsc checkout to build one")
|
|
77
|
+
if len(blobs) > 1:
|
|
78
|
+
raise RuntimeError(
|
|
79
|
+
f"{PAYLOAD_DIR} carries {len(blobs)} blobs "
|
|
80
|
+
f"({[b.name for b in blobs]}) — exactly one is expected; a stale "
|
|
81
|
+
"blob from a previous seal was not cleaned up")
|
|
82
|
+
blob_path = blobs[0]
|
|
83
|
+
claimed_digest = blob_path.stem
|
|
84
|
+
headers, host_only_names = _unpack(blob_path.read_bytes())
|
|
85
|
+
actual_digest = digest_of(headers)
|
|
86
|
+
if actual_digest != claimed_digest:
|
|
87
|
+
raise ValueError(
|
|
88
|
+
f"{blob_path} is named for digest {claimed_digest} but its content "
|
|
89
|
+
f"digests to {actual_digest} — corrupt or hand-edited blob")
|
|
90
|
+
_PAYLOAD_CACHE = Payload(actual_digest, headers, host_only_names)
|
|
91
|
+
return _PAYLOAD_CACHE
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _reset_payload_cache() -> None:
|
|
95
|
+
"""Test/dev hook: forget the cached :func:`payload` so a re-seal (or a
|
|
96
|
+
freshly written blob in a test's tmp `_payload/` dir) is picked up
|
|
97
|
+
without restarting the process."""
|
|
98
|
+
global _PAYLOAD_CACHE
|
|
99
|
+
_PAYLOAD_CACHE = None
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Copyright 2026 Alessandro Masat
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""The `Payload` type and its (de)serialisation — everything `aether_dsc`
|
|
5
|
+
needs at IMPORT time, with zero third-party dependencies. Kept apart
|
|
6
|
+
from :mod:`aether_dsc.seal`, which needs `cuda-bindings` for its NVRTC-clean
|
|
7
|
+
gate: an ordinary consumer who only ever calls `payload()`/`.serve()` must
|
|
8
|
+
never pay for (or need installed) a CUDA binding just to unpack a blob.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import contextlib
|
|
13
|
+
import hashlib
|
|
14
|
+
import io
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import tarfile
|
|
18
|
+
import tempfile
|
|
19
|
+
import zlib
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Iterator, Mapping
|
|
22
|
+
|
|
23
|
+
__all__ = ["Payload", "PAYLOAD_DIR", "digest_of"]
|
|
24
|
+
|
|
25
|
+
#: Where a sealed blob lives once `python -m aether_dsc.seal` has written one
|
|
26
|
+
#: — `aether_dsc/_payload/<digest>.bin`, shipped as package data.
|
|
27
|
+
PAYLOAD_DIR = Path(__file__).resolve().parent / "_payload"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def digest_of(headers: Mapping[str, bytes]) -> str:
|
|
31
|
+
"""The payload's content digest: sha256 over the
|
|
32
|
+
SORTED `(name, bytes)` pairs. Sorting is what makes it order-independent
|
|
33
|
+
— two payloads built by walking the same files in a different order (a
|
|
34
|
+
different filesystem, a different `os.walk` order) still digest to the
|
|
35
|
+
same value, and a single renamed or altered file changes it.
|
|
36
|
+
"""
|
|
37
|
+
h = hashlib.sha256()
|
|
38
|
+
for name in sorted(headers):
|
|
39
|
+
encoded = name.encode()
|
|
40
|
+
h.update(len(encoded).to_bytes(4, "big"))
|
|
41
|
+
h.update(encoded)
|
|
42
|
+
data = headers[name]
|
|
43
|
+
h.update(len(data).to_bytes(8, "big"))
|
|
44
|
+
h.update(data)
|
|
45
|
+
return h.hexdigest()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#: The tar member :func:`_pack`/:func:`_unpack` use to carry the host-only
|
|
49
|
+
#: name set through the blob. Never a real header's own name — every real
|
|
50
|
+
#: payload entry spells ``aether/...``, ``rtc/...`` or ``plugin/...``, so a
|
|
51
|
+
#: bare dunder name with no such prefix cannot collide with one, now or as
|
|
52
|
+
#: the manifests grow.
|
|
53
|
+
_HOST_ONLY_MANIFEST_MEMBER = "__host_only_names__"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _pack(headers: Mapping[str, bytes],
|
|
57
|
+
host_only_names: frozenset[str] = frozenset()) -> bytes:
|
|
58
|
+
"""Serialise `headers` (both sections — NVRTC-clean and host-only —
|
|
59
|
+
already merged into one mapping by the caller) to the on-disk blob
|
|
60
|
+
format: a zlib-compressed tar, one member per header plus one more
|
|
61
|
+
(:data:`_HOST_ONLY_MANIFEST_MEMBER`) naming which of those members are
|
|
62
|
+
host-only, newline-joined and sorted. Opacity, not secrecy, so a viewer
|
|
63
|
+
cannot casually `strings` or `cat` the payload."""
|
|
64
|
+
buf = io.BytesIO()
|
|
65
|
+
with tarfile.open(fileobj=buf, mode="w") as tf:
|
|
66
|
+
for name in sorted(headers):
|
|
67
|
+
data = headers[name]
|
|
68
|
+
info = tarfile.TarInfo(name=name)
|
|
69
|
+
info.size = len(data)
|
|
70
|
+
tf.addfile(info, io.BytesIO(data))
|
|
71
|
+
if host_only_names:
|
|
72
|
+
data = "\n".join(sorted(host_only_names)).encode()
|
|
73
|
+
info = tarfile.TarInfo(name=_HOST_ONLY_MANIFEST_MEMBER)
|
|
74
|
+
info.size = len(data)
|
|
75
|
+
tf.addfile(info, io.BytesIO(data))
|
|
76
|
+
return zlib.compress(buf.getvalue(), level=9)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _unpack(blob: bytes) -> tuple[dict[str, bytes], frozenset[str]]:
|
|
80
|
+
"""The inverse of :func:`_pack`: ``(headers, host_only_names)`` — the
|
|
81
|
+
latter empty when the blob predates the host-only section (an older
|
|
82
|
+
payload sealed only the NVRTC-clean set)."""
|
|
83
|
+
raw = zlib.decompress(blob)
|
|
84
|
+
headers: dict[str, bytes] = {}
|
|
85
|
+
host_only_names: frozenset[str] = frozenset()
|
|
86
|
+
with tarfile.open(fileobj=io.BytesIO(raw), mode="r") as tf:
|
|
87
|
+
for member in tf.getmembers():
|
|
88
|
+
if not member.isfile():
|
|
89
|
+
continue
|
|
90
|
+
extracted = tf.extractfile(member)
|
|
91
|
+
data = extracted.read() if extracted else b""
|
|
92
|
+
if member.name == _HOST_ONLY_MANIFEST_MEMBER:
|
|
93
|
+
host_only_names = frozenset(
|
|
94
|
+
ln for ln in data.decode().splitlines() if ln)
|
|
95
|
+
else:
|
|
96
|
+
headers[member.name] = data
|
|
97
|
+
return headers, host_only_names
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _is_tmpfs(path: Path) -> bool:
|
|
101
|
+
"""Whether `path` is itself a tmpfs mount (prefer `/dev/shm` when it is
|
|
102
|
+
one). Read from `/proc/mounts` rather than assumed from the name —
|
|
103
|
+
`/dev/shm` is conventional, not guaranteed, and measurement found a box
|
|
104
|
+
where a private tmpfs mount is refused entirely (SELinux enforcing), so
|
|
105
|
+
this function only ever REPORTS what is already mounted, never mounts
|
|
106
|
+
anything itself."""
|
|
107
|
+
try:
|
|
108
|
+
target = str(path.resolve())
|
|
109
|
+
except OSError:
|
|
110
|
+
return False
|
|
111
|
+
try:
|
|
112
|
+
with open("/proc/mounts") as f:
|
|
113
|
+
for line in f:
|
|
114
|
+
parts = line.split()
|
|
115
|
+
if len(parts) >= 3 and parts[1] == target and parts[2] == "tmpfs":
|
|
116
|
+
return True
|
|
117
|
+
except OSError:
|
|
118
|
+
return False
|
|
119
|
+
return False
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _ram_dir() -> Path:
|
|
123
|
+
"""Where :meth:`Payload.serve` stages files: `/dev/shm` when it is a
|
|
124
|
+
tmpfs, else `$TMPDIR` (the measured fallback when a private mount
|
|
125
|
+
namespace is refused)."""
|
|
126
|
+
shm = Path("/dev/shm")
|
|
127
|
+
if shm.is_dir() and _is_tmpfs(shm):
|
|
128
|
+
return shm
|
|
129
|
+
return Path(os.environ.get("TMPDIR", "/tmp"))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class Payload:
|
|
133
|
+
"""A sealed set of headers plus its content digest.
|
|
134
|
+
|
|
135
|
+
`headers` maps include-relative names (`aether/...`, `rtc/<std name>`,
|
|
136
|
+
`plugin/gref_layout.h`) to their bytes; `digest` is :func:`digest_of`
|
|
137
|
+
applied to that mapping — two `Payload` instances with the same file set and
|
|
138
|
+
content always carry the same digest, independent of how or in what
|
|
139
|
+
order their files were discovered (:mod:`aether_dsc.seal`'s own
|
|
140
|
+
order-independence guarantee, exercised by
|
|
141
|
+
`tests/test_aether_dsc.py::test_seal_digest_order_independent`).
|
|
142
|
+
|
|
143
|
+
`host_only_names` names the subset of `headers` that is the HOST-ONLY
|
|
144
|
+
section: sealed (so :meth:`serve` writes them out for a host `-I` root
|
|
145
|
+
exactly like every other entry) but never claimed NVRTC-clean and never
|
|
146
|
+
handed to an NVRTC compile — see :attr:`device_headers`. `digest` covers
|
|
147
|
+
`headers` whole, host-only entries included, so a changed host-only file
|
|
148
|
+
changes the digest too (the cache-validity term every compile keys on).
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
__slots__ = ("digest", "headers", "host_only_names")
|
|
152
|
+
|
|
153
|
+
def __init__(self, digest: str, headers: Mapping[str, bytes],
|
|
154
|
+
host_only_names: frozenset[str] = frozenset()):
|
|
155
|
+
self.digest = digest
|
|
156
|
+
self.headers = dict(headers)
|
|
157
|
+
self.host_only_names = frozenset(host_only_names)
|
|
158
|
+
|
|
159
|
+
def __repr__(self) -> str: # pragma: no cover - debugging aid
|
|
160
|
+
return (f"Payload(digest={self.digest[:12]}…, {len(self.headers)} headers, "
|
|
161
|
+
f"{len(self.host_only_names)} host-only)")
|
|
162
|
+
|
|
163
|
+
@property
|
|
164
|
+
def device_headers(self) -> dict[str, bytes]:
|
|
165
|
+
"""`headers` minus the host-only section — what an NVRTC compile is
|
|
166
|
+
actually served (:mod:`hawk.compile.drivers`'s device path,
|
|
167
|
+
:mod:`hawk.compile.nvrtc`'s public ``device``/``cubin``): the
|
|
168
|
+
host-only headers are never NVRTC-clean-checked and must never
|
|
169
|
+
reach NVRTC even as an unreferenced, served-but-unused file."""
|
|
170
|
+
if not self.host_only_names:
|
|
171
|
+
return self.headers
|
|
172
|
+
return {k: v for k, v in self.headers.items() if k not in self.host_only_names}
|
|
173
|
+
|
|
174
|
+
@contextlib.contextmanager
|
|
175
|
+
def serve(self) -> Iterator[Path]:
|
|
176
|
+
"""Materialise every header into a PRIVATE, owner-only directory for
|
|
177
|
+
the compile's lifetime, then remove it — on the normal exit path and
|
|
178
|
+
when the `with` block raises.
|
|
179
|
+
|
|
180
|
+
Prefers a tmpfs (`/dev/shm`, checked via `/proc/mounts` — never
|
|
181
|
+
assumed from the path alone) so nothing touches spinning or
|
|
182
|
+
networked storage; falls back to `$TMPDIR` otherwise. A private
|
|
183
|
+
mount namespace with its own tmpfs is an opportunistic upgrade this
|
|
184
|
+
function does not attempt: measurement found it refused outright on
|
|
185
|
+
an SELinux-enforcing box, so the plain RAM directory is the one
|
|
186
|
+
path every caller can rely on.
|
|
187
|
+
"""
|
|
188
|
+
base = _ram_dir()
|
|
189
|
+
base.mkdir(parents=True, exist_ok=True)
|
|
190
|
+
served = Path(tempfile.mkdtemp(prefix="aether_dsc_", dir=str(base)))
|
|
191
|
+
os.chmod(served, 0o700)
|
|
192
|
+
try:
|
|
193
|
+
for name, data in self.headers.items():
|
|
194
|
+
dest = served / name
|
|
195
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
196
|
+
dest.write_bytes(data)
|
|
197
|
+
os.chmod(dest, 0o600)
|
|
198
|
+
yield served
|
|
199
|
+
finally:
|
|
200
|
+
shutil.rmtree(served, ignore_errors=True)
|