-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
15 changed files
with
593 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
|
||
import json | ||
import sys | ||
import os | ||
import hashlib | ||
|
||
source, checksum = sys.argv[1:3] | ||
|
||
BLOCKSIZE=65536 | ||
crate_files = {} | ||
|
||
for root, dirs, files in os.walk(source): | ||
for f in files: | ||
if f in ['.gitattributes', '.gitignore', '.cargo-ok', '.cargo-checksum.json', '.cargo_vcs_info.json']: | ||
continue | ||
if f.endswith('.rej') or f.endswith('.orig'): | ||
continue | ||
|
||
fpath = os.path.join(root, f) | ||
rpath = os.path.relpath(fpath, source) | ||
|
||
hasher = hashlib.sha256() | ||
with open(fpath, 'rb') as fp: | ||
buf = fp.read(BLOCKSIZE) | ||
while len(buf) > 0: | ||
hasher.update(buf) | ||
buf = fp.read(BLOCKSIZE) | ||
|
||
crate_files[rpath] = hasher.hexdigest() | ||
|
||
output = { | ||
"files": crate_files, | ||
"package": checksum | ||
} | ||
|
||
out = json.dumps(output, separators=(',', ':'), sort_keys=True) | ||
|
||
sys.stdout.write(out) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ pkgs ? import <nixpkgs> {} | ||
}: | ||
|
||
with pkgs.python3Packages; | ||
|
||
buildPythonApplication { | ||
pname = "merge-cargo-lock"; | ||
version = "0.0.1"; | ||
|
||
propagatedBuildInputs = [ | ||
toml | ||
]; | ||
|
||
src = ./.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
|
||
import toml | ||
import sys | ||
|
||
source = sys.argv[1] | ||
|
||
with open(source) as f: | ||
content = toml.load(f) | ||
|
||
# first rewrite rust dependencies to make sure they are version pinned | ||
for p in content['package']: | ||
if p.get('source') == 'registry+https://github.com/rust-lang/crates.io-index': | ||
print("https://crates.io/api/v1/crates/%s/%s/download %s-%s %s" % (p['name'], p['version'], p['name'], p['version'], p['checksum'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
|
||
import toml | ||
import sys | ||
|
||
source, rust = sys.argv[1:3] | ||
|
||
with open(source) as f: | ||
origin_content = toml.load(f) | ||
|
||
with open(rust) as f: | ||
rust_content = toml.load(f) | ||
|
||
# first rewrite rust dependencies to make sure they are version pinned | ||
package_versions = {} | ||
for p in rust_content['package']: | ||
if p['name'] in package_versions: | ||
package_versions[p['name']].append(p['version']) | ||
else: | ||
package_versions[p['name']] = [p['version']] | ||
|
||
for p in rust_content['package']: | ||
if 'dependencies' in p: | ||
deps = [] | ||
for dep in p['dependencies']: | ||
if ' ' in dep: | ||
deps.append(dep) | ||
else: | ||
deps.append(dep + " " + package_versions[dep][0]) | ||
p['dependencies'] = deps | ||
|
||
# do the same with the origin ones | ||
origin_packages = set() | ||
package_versions = {} | ||
for p in origin_content['package']: | ||
origin_packages.add((p['name'], p['version'])) | ||
|
||
if p['name'] in package_versions: | ||
package_versions[p['name']].append(p['version']) | ||
else: | ||
package_versions[p['name']] = [p['version']] | ||
|
||
for p in origin_content['package']: | ||
if 'dependencies' in p: | ||
deps = [] | ||
for dep in p['dependencies']: | ||
if ' ' in dep: | ||
deps.append(dep) | ||
else: | ||
deps.append(dep + " " + package_versions[dep][0]) | ||
p['dependencies'] = deps | ||
|
||
|
||
# then merge the rust in the origin ones | ||
# to do that, we can't add the same dependency twice. | ||
# TODO: do we need to care about the dependencies? (make it a super set?) | ||
for p in rust_content['package']: | ||
tup = (p['name'], p['version']) | ||
if tup not in origin_packages: | ||
origin_content['package'].append(p) | ||
|
||
output = toml.dumps(origin_content) | ||
print(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup(name='cargo-lock-utils', | ||
version='0.0.1', | ||
packages=find_packages(), | ||
scripts=[ | ||
'compute-checksum', | ||
'list-cargo-lock', | ||
'merge-cargo-lock', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[unstable] | ||
build-std = ["core", "compiler_builtins", "alloc"] | ||
build-std-features = [ "compiler-builtins-mem" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "nested-partition-loader" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
uefi = { path = "uefi-rs", features = [ "exts", "logger" ] } | ||
uefi-services = { path = "uefi-rs/uefi-services" } | ||
|
||
log = { version = "0.4.11", default-features = false } | ||
|
||
[patch.crates-io] | ||
uefi-macros = { path = "uefi-rs/uefi-macros" } | ||
uefi = { path = "uefi-rs" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cargoRewriteConfigHook() { | ||
echo "LASJKDLKAJSD" | ||
cat .cargo/config | ||
|
||
set -x | ||
echo @mergeCargoLock@ | ||
|
||
# cat >> .cargo/config <<EOF | ||
#[source."library"] | ||
#"directory" = "/nix/store/iz8h5l1q4r8dqg88rwqapyi1p4ygcfv4-rust-src/lib/rustlib/src/rust/library/" | ||
#EOF | ||
cat .cargo/config | ||
} | ||
|
||
if [ -z "${dontCargoRewriteConfig-}" ]; then | ||
postUnpackHooks+=(cargoRewriteConfigHook) | ||
fi |
Oops, something went wrong.
e108c50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baloo, thanks for the workaround for the
cargo vendor
bug, it works great!I'm curious about the licensing of this code. I checked the repository (baloo/nixos-firmware) but it doesn't have any LICENSE files as far as I can see. Can we use this code on Apache 2.0 licensed open-source code? Would it be possible for you to add a LICENSE file to the nixos-firmware project?
I'm not an expert in OS licensing, but I think when a code does not have a LICENSE file then you have to assume the worst and cannot use the code.
e108c50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@osa1 I don't know much about Apache2.0, but I'd be comfortable pushing a bsd-2-clause license if that works for you.
also, please mind I'm doing "tricks" with the checksums. I believe the model is correct since I'm trusting the checksum already available in the Cargo.lock which is then used to verify the checksums.json file but, no guarantees, please review that carefully.
e108c50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also please tag me again, so that it pops up in my notification and I don't forget :D)
e108c50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@osa1 f15b35f