Skip to content

Commit e108c50

Browse files
committed
initial commit of nested-partition-loader
This include a workaround for cargo-vendor being unable to vendor compiler's dependencies. It will load rust's Cargo.lock and manually version every component in a nix derivation. Both project and rust cargo vendor are then merged together (with symlinks) and provided for cargo to use. Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
1 parent 6355e24 commit e108c50

File tree

15 files changed

+593
-0
lines changed

15 files changed

+593
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
import sys
5+
import os
6+
import hashlib
7+
8+
source, checksum = sys.argv[1:3]
9+
10+
BLOCKSIZE=65536
11+
crate_files = {}
12+
13+
for root, dirs, files in os.walk(source):
14+
for f in files:
15+
if f in ['.gitattributes', '.gitignore', '.cargo-ok', '.cargo-checksum.json', '.cargo_vcs_info.json']:
16+
continue
17+
if f.endswith('.rej') or f.endswith('.orig'):
18+
continue
19+
20+
fpath = os.path.join(root, f)
21+
rpath = os.path.relpath(fpath, source)
22+
23+
hasher = hashlib.sha256()
24+
with open(fpath, 'rb') as fp:
25+
buf = fp.read(BLOCKSIZE)
26+
while len(buf) > 0:
27+
hasher.update(buf)
28+
buf = fp.read(BLOCKSIZE)
29+
30+
crate_files[rpath] = hasher.hexdigest()
31+
32+
output = {
33+
"files": crate_files,
34+
"package": checksum
35+
}
36+
37+
out = json.dumps(output, separators=(',', ':'), sort_keys=True)
38+
39+
sys.stdout.write(out)
40+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ pkgs ? import <nixpkgs> {}
2+
}:
3+
4+
with pkgs.python3Packages;
5+
6+
buildPythonApplication {
7+
pname = "merge-cargo-lock";
8+
version = "0.0.1";
9+
10+
propagatedBuildInputs = [
11+
toml
12+
];
13+
14+
src = ./.;
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
3+
import toml
4+
import sys
5+
6+
source = sys.argv[1]
7+
8+
with open(source) as f:
9+
content = toml.load(f)
10+
11+
# first rewrite rust dependencies to make sure they are version pinned
12+
for p in content['package']:
13+
if p.get('source') == 'registry+https://github.com/rust-lang/crates.io-index':
14+
print("https://crates.io/api/v1/crates/%s/%s/download %s-%s %s" % (p['name'], p['version'], p['name'], p['version'], p['checksum']))
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
3+
import toml
4+
import sys
5+
6+
source, rust = sys.argv[1:3]
7+
8+
with open(source) as f:
9+
origin_content = toml.load(f)
10+
11+
with open(rust) as f:
12+
rust_content = toml.load(f)
13+
14+
# first rewrite rust dependencies to make sure they are version pinned
15+
package_versions = {}
16+
for p in rust_content['package']:
17+
if p['name'] in package_versions:
18+
package_versions[p['name']].append(p['version'])
19+
else:
20+
package_versions[p['name']] = [p['version']]
21+
22+
for p in rust_content['package']:
23+
if 'dependencies' in p:
24+
deps = []
25+
for dep in p['dependencies']:
26+
if ' ' in dep:
27+
deps.append(dep)
28+
else:
29+
deps.append(dep + " " + package_versions[dep][0])
30+
p['dependencies'] = deps
31+
32+
# do the same with the origin ones
33+
origin_packages = set()
34+
package_versions = {}
35+
for p in origin_content['package']:
36+
origin_packages.add((p['name'], p['version']))
37+
38+
if p['name'] in package_versions:
39+
package_versions[p['name']].append(p['version'])
40+
else:
41+
package_versions[p['name']] = [p['version']]
42+
43+
for p in origin_content['package']:
44+
if 'dependencies' in p:
45+
deps = []
46+
for dep in p['dependencies']:
47+
if ' ' in dep:
48+
deps.append(dep)
49+
else:
50+
deps.append(dep + " " + package_versions[dep][0])
51+
p['dependencies'] = deps
52+
53+
54+
# then merge the rust in the origin ones
55+
# to do that, we can't add the same dependency twice.
56+
# TODO: do we need to care about the dependencies? (make it a super set?)
57+
for p in rust_content['package']:
58+
tup = (p['name'], p['version'])
59+
if tup not in origin_packages:
60+
origin_content['package'].append(p)
61+
62+
output = toml.dumps(origin_content)
63+
print(output)

packages/cargo-lock-utils/setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
3+
from setuptools import setup, find_packages
4+
5+
setup(name='cargo-lock-utils',
6+
version='0.0.1',
7+
packages=find_packages(),
8+
scripts=[
9+
'compute-checksum',
10+
'list-cargo-lock',
11+
'merge-cargo-lock',
12+
],
13+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[unstable]
2+
build-std = ["core", "compiler_builtins", "alloc"]
3+
build-std-features = [ "compiler-builtins-mem" ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

packages/nested-partition-loader/Cargo.lock

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "nested-partition-loader"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
uefi = { path = "uefi-rs", features = [ "exts", "logger" ] }
10+
uefi-services = { path = "uefi-rs/uefi-services" }
11+
12+
log = { version = "0.4.11", default-features = false }
13+
14+
[patch.crates-io]
15+
uefi-macros = { path = "uefi-rs/uefi-macros" }
16+
uefi = { path = "uefi-rs" }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cargoRewriteConfigHook() {
2+
echo "LASJKDLKAJSD"
3+
cat .cargo/config
4+
5+
set -x
6+
echo @mergeCargoLock@
7+
8+
# cat >> .cargo/config <<EOF
9+
#[source."library"]
10+
#"directory" = "/nix/store/iz8h5l1q4r8dqg88rwqapyi1p4ygcfv4-rust-src/lib/rustlib/src/rust/library/"
11+
#EOF
12+
cat .cargo/config
13+
}
14+
15+
if [ -z "${dontCargoRewriteConfig-}" ]; then
16+
postUnpackHooks+=(cargoRewriteConfigHook)
17+
fi

0 commit comments

Comments
 (0)