summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-06-27 17:30:33 +0200
committerGitHub <noreply@github.com>2024-06-27 17:30:33 +0200
commitf46b8e21e0013eeb04a2944dc85be327a896ffe7 (patch)
tree8997065bb29dcdd09fbe8f131680f2377c063e70
parent05b2d6fc51146fe07340a58bc87fbbd99e788143 (diff)
parent3c54e850a32e4250c36bee3f118df977c3e8773d (diff)
downloadhello-nix-f46b8e21e0013eeb04a2944dc85be327a896ffe7.tar.gz
Merge pull request #4 from aehlig/simplify-cargo-import
Simplify cargo import
-rw-r--r--README.md8
-rw-r--r--etc/defaults/rust/TARGETS.cargo_import (renamed from etc/defaults/rust/TARGETS)0
-rwxr-xr-xetc/generate-repos.sh7
-rw-r--r--etc/repos.json13
-rw-r--r--etc/repos.template.json8
-rw-r--r--nix-dependencies/dependencies.nix11
-rw-r--r--nix-import-tools/import-tools.nix4
-rwxr-xr-xrun-tests1
-rw-r--r--shell.nix1
-rw-r--r--src/rust/cargo/README.md15
10 files changed, 34 insertions, 34 deletions
diff --git a/README.md b/README.md
index 5ab1a0d..1ae6676 100644
--- a/README.md
+++ b/README.md
@@ -73,7 +73,8 @@ way as follows.
pinned using [niv](https://github.com/nmattia/niv).
- A [nix shell](./shell.nix) uses the derivation at the pinned
snapshot of the `nixpkgs` and sets an alias for `just-mr` to
- use the derived rc-file.
+ use the derived rc-file. It also adds a script `withRc-just-mr`
+ that execs `just-mr` with the derived rc-file.
So to build with the correct dependencies for the checked out version,
simply start a `nix-shell` at the top level of this repository and
@@ -90,6 +91,11 @@ by using the current justbuild when checking out older snapshots,
we can reconstruct the old actions without the need of cleaning up
the local build root.
+The just described way of working in a `nix-shell` using the
+alias is useful for interactive development. For CI-like usage,
+the script [run-tests](./run-tests) can be used that simply runs
+`withRc-just-mr` in a `nix-shell`.
+
## Shell commands
The built-in rule `"generic"` allows to define a target by
diff --git a/etc/defaults/rust/TARGETS b/etc/defaults/rust/TARGETS.cargo_import
index fe4de0a..fe4de0a 100644
--- a/etc/defaults/rust/TARGETS
+++ b/etc/defaults/rust/TARGETS.cargo_import
diff --git a/etc/generate-repos.sh b/etc/generate-repos.sh
index d8cd187..4235fd0 100755
--- a/etc/generate-repos.sh
+++ b/etc/generate-repos.sh
@@ -9,14 +9,13 @@ readonly ROOT=$(readlink -f $(dirname $0)/..)
: ${RULES_RUST_BRANCH:=master}
# remove files generated by just-import-cargo
-rm -rf etc/deps-rust etc/defaults/rust/TARGETS # common to all cargo imports
-rm -f src/rust/cargo/circle/Cargo.lock src/rust/cargo/circle/TARGETS
+rm -rf etc/deps-rust etc/defaults/rust/TARGETS.cargo_import # common to all cargo imports
+rm -f src/rust/cargo/circle/Cargo.lock src/rust/cargo/circle/TARGETS # crate
just-import-git -C ${ROOT}/etc/repos.template.json \
--as rules -b ${RULES_CC_BRANCH} ${RULES_CC_REPO} rules \
| just-import-git -C - \
--as rules-rust -b ${RULES_RUST_BRANCH} ${RULES_RUST_REPO} rules-rust \
- | just-import-cargo --rules rules-rust/nix --repo-root ${ROOT} -rst \
- src/rust/cargo/circle \
+ | just-import-cargo --repo-root ${ROOT} -rst src/rust/cargo/circle \
| just-deduplicate-repos \
| hdump > ${ROOT}/etc/repos.json
diff --git a/etc/repos.json b/etc/repos.json
index 3f419a3..4ac3809 100644
--- a/etc/repos.json
+++ b/etc/repos.json
@@ -1,7 +1,7 @@
{ "repositories":
{ "":
{ "repository": {"type": "file", "path": "src"}
- , "bindings": {"rules": "rules/nix", "rust": "rules-rust/nix"}
+ , "bindings": {"rules": "rules/nix", "rust": "rules-rust"}
}
, "test":
{ "repository": {"type": "file", "path": "test"}
@@ -11,12 +11,6 @@
, "defaults": {"repository": {"type": "file", "path": "etc/defaults"}}
, "rules/nix":
{"repository": "rules", "target_root": "defaults", "rule_root": "rules"}
- , "rules-rust/nix":
- { "repository": "rules-rust"
- , "target_root": "defaults"
- , "rule_root": "rules-rust"
- , "target_file_name": "nix.TARGETS"
- }
, "rules/nix-test":
{ "repository": "rules"
, "target_root": "defaults"
@@ -38,7 +32,7 @@
{ "type": "git"
, "repository": "https://github.com/just-buildsystem/rules-rust"
, "branch": "master"
- , "commit": "9a4697a2c948a4bcb4a2232a371b6cb3c178e20b"
+ , "commit": "1a8211bda5c14ef0b2bff3af062c049d5598f02f"
, "subdir": "rules"
}
}
@@ -155,7 +149,8 @@
{ "repository": "rules-rust"
, "target_root": "defaults"
, "rule_root": "rules-rust"
- , "bindings": {"orig-rules": "rules-rust/nix"}
+ , "bindings": {"orig-rules": "rules-rust"}
+ , "target_file_name": "TARGETS.cargo_import"
}
}
}
diff --git a/etc/repos.template.json b/etc/repos.template.json
index 1b898be..33e6acc 100644
--- a/etc/repos.template.json
+++ b/etc/repos.template.json
@@ -1,7 +1,7 @@
{ "repositories":
{ "":
{ "repository": {"type": "file", "path": "src"}
- , "bindings": {"rules": "rules/nix", "rust": "rules-rust/nix"}
+ , "bindings": {"rules": "rules/nix", "rust": "rules-rust"}
}
, "test":
{ "repository": {"type": "file", "path": "test"}
@@ -11,12 +11,6 @@
, "defaults": {"repository": {"type": "file", "path": "etc/defaults"}}
, "rules/nix":
{"repository": "rules", "target_root": "defaults", "rule_root": "rules"}
- , "rules-rust/nix":
- { "repository": "rules-rust"
- , "target_root": "defaults"
- , "rule_root": "rules-rust"
- , "target_file_name": "nix.TARGETS"
- }
, "rules/nix-test":
{ "repository": "rules"
, "target_root": "defaults"
diff --git a/nix-dependencies/dependencies.nix b/nix-dependencies/dependencies.nix
index 10a1b3e..2e73468 100644
--- a/nix-dependencies/dependencies.nix
+++ b/nix-dependencies/dependencies.nix
@@ -1,5 +1,6 @@
{ stdenv
, jo
+, bash
, pkg-config
, coreutils
, protobuf_25
@@ -25,6 +26,7 @@ stdenv.mkDerivation rec {
protobuf_25
grpc
jo
+ bash
];
buildInputs = [
@@ -52,12 +54,19 @@ stdenv.mkDerivation rec {
) > config.json
cat config.json
jo "just files"=$(jo config=$(jo -a $(jo root=system path=$out/share/config.json))) > rc.json
+
+ cat > withRc-just-mr <<EOF
+ #!${bash}/bin/bash
+ exec just-mr --rc $out/share/rc.json "\$@"
+ EOF
'';
installPhase = ''
- mkdir -p $out/share
+ mkdir -p $out/share $out/bin
cp config.json $out/share
cp rc.json $out/share
+ cp withRc-just-mr $out/bin
+ chmod 555 $out/bin/withRc-just-mr
'';
}
diff --git a/nix-import-tools/import-tools.nix b/nix-import-tools/import-tools.nix
index b12023b..3f34f4b 100644
--- a/nix-import-tools/import-tools.nix
+++ b/nix-import-tools/import-tools.nix
@@ -19,8 +19,8 @@ stdenv.mkDerivation rec {
srcrustrules = fetchFromGitHub {
owner = "just-buildsystem";
repo = "rules-rust";
- rev = "bf3e05a614f1de5a9a8a0f8e40f1dd9e1f6609da";
- sha256 = "sha256-8y10ZmZpeTGtbkIeneaVISyMbVKfIi3gHqyvztnKn0M=";
+ rev = "1a8211bda5c14ef0b2bff3af062c049d5598f02f";
+ sha256 = "sha256-97VbtMp5B/5CtOp9U7J6FNB6omlG/YOfMIBFAsaOyjs=";
};
diff --git a/run-tests b/run-tests
new file mode 100755
index 0000000..c3d4938
--- /dev/null
+++ b/run-tests
@@ -0,0 +1 @@
+nix-shell --run "withRc-just-mr --main test build"
diff --git a/shell.nix b/shell.nix
index a42d2ae..70c8edd 100644
--- a/shell.nix
+++ b/shell.nix
@@ -17,6 +17,7 @@ in pkgs.mkShell rec {
niv
update-deps
cargo
+ nix-dependencies
];
shellHook = ''
diff --git a/src/rust/cargo/README.md b/src/rust/cargo/README.md
index 5ac8e27..4e6d59a 100644
--- a/src/rust/cargo/README.md
+++ b/src/rust/cargo/README.md
@@ -19,12 +19,8 @@ on standard input and returns one on standard output. It needs to know
- the root of the pyhsical repository, and
- the location of the crate directory, relative to the root of the physical
repository.
- - the name of the already imported `rules-rust` repository.
-
-While the tool in general can also import `rules-rust` itself, we need to import
-the rules manually first, as we have to provide our own target root for the
-defaults. Future versions of the rules might bring a defaults target suitable
-for our use case, but so far this is not the case.
+ - the name of the already imported `rules-rust` repository, if desired
+ (otherwise it will default to the upstream rust rules).
The name of the imported main repository is the crate name (without version),
as specified in the `Cargo.toml` file. Some care should be taken that is does
@@ -36,10 +32,9 @@ As opposed to other import tools, however, `just-import-cargo` also creates
files in the pysical repository. Those are the following.
- In the crate the file `Cargo.lock` generated by the call to cargo, as
well as a target file,
- - The file `etc/defaults/rust/TARGETS` relative to in the top-level of the
- physical repository (with a content independent of the respective crate).
- This file is the reason that our `rules-rust/nix` use `nix.TARGETS` as
- target-file name.
+ - The file `etc/defaults/rust/TARGETS.cargo_import` relative to
+ in the top-level of the physical repository (with a content
+ independent of the respective crate).
- In the directory `etc/deps-rust` target files for all the imported crates.
As their name encode crate name and version, calling `just-import-cargo`
for several crates should not cause a conflict here.