summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus T. Aehlig <aehlig@linta.de>2024-06-25 17:59:39 +0200
committerKlaus T. Aehlig <aehlig@linta.de>2024-06-25 18:29:41 +0200
commite65cf1d265210738a9b3c0b811fbfeffa0741c39 (patch)
tree3b1bfe9958b324b5bd0768b48bfa76aaaa3eecc7
parent628cb0ab06332086a7ea022bcebfb69d95c38068 (diff)
downloadhello-nix-e65cf1d265210738a9b3c0b811fbfeffa0741c39.tar.gz
Import rust rules and add a minimal example
Note that the PATH for rust targets also has to include that for the C compiler and hence also coreutils, as the rust compiler calls out to `cc`.
-rw-r--r--etc/defaults/rust/TARGETS43
-rwxr-xr-xetc/generate-repos.sh4
-rw-r--r--etc/repos.json16
-rw-r--r--etc/repos.template.json7
-rw-r--r--nix-dependencies/dependencies.nix2
-rw-r--r--src/rust/hello/TARGETS6
-rw-r--r--src/rust/hello/main.rs3
-rw-r--r--test/TARGETS1
-rw-r--r--test/rust/TARGETS8
-rw-r--r--test/rust/hello/TARGETS8
-rw-r--r--test/rust/hello/test_hello.sh3
11 files changed, 99 insertions, 2 deletions
diff --git a/etc/defaults/rust/TARGETS b/etc/defaults/rust/TARGETS
new file mode 100644
index 0000000..fbd1a69
--- /dev/null
+++ b/etc/defaults/rust/TARGETS
@@ -0,0 +1,43 @@
+{ "defaults":
+ { "type": "configure"
+ , "target": "defaults (unconfigured)"
+ , "arguments_config": ["TOOLCHAIN_CONFIG"]
+ , "config":
+ { "type": "let*"
+ , "bindings":
+ [ [ "toolchain"
+ , { "type": "lookup"
+ , "map":
+ { "type": "var"
+ , "name": "TOOLCHAIN_CONFIG"
+ , "default": {"type": "empty_map"}
+ }
+ , "key": "RUST"
+ , "default": {"type": "empty_map"}
+ }
+ ]
+ , [ "RUSTC"
+ , { "type": "lookup"
+ , "map": {"type": "var", "name": "toolchain"}
+ , "key": "RUSTC"
+ , "default": "rustc"
+ }
+ ]
+ , [ "PATH"
+ , { "type": "lookup"
+ , "map": {"type": "var", "name": "toolchain"}
+ , "key": "PATH"
+ , "default": []
+ }
+ ]
+ ]
+ , "body": {"type": "env", "vars": ["RUSTC", "PATH"]}
+ }
+ }
+, "defaults (unconfigured)":
+ { "type": "defaults"
+ , "arguments_config": ["RUSTC", "PATH"]
+ , "RUSTC": [{"type": "var", "name": "RUSTC"}]
+ , "PATH": {"type": "var", "name": "PATH"}
+ }
+}
diff --git a/etc/generate-repos.sh b/etc/generate-repos.sh
index f7b4cf8..8bd1ca6 100755
--- a/etc/generate-repos.sh
+++ b/etc/generate-repos.sh
@@ -5,7 +5,11 @@ readonly ROOT=$(readlink -f $(dirname $0)/..)
: ${RULES_CC_REPO:=https://github.com/just-buildsystem/rules-cc}
: ${RULES_CC_BRANCH:=master}
+: ${RULES_RUST_REPO:=https://github.com/just-buildsystem/rules-rust}
+: ${RULES_RUST_BRANCH:=master}
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 \
| hdump > ${ROOT}/etc/repos.json
diff --git a/etc/repos.json b/etc/repos.json
index 5ab3477..1f68227 100644
--- a/etc/repos.json
+++ b/etc/repos.json
@@ -1,7 +1,7 @@
{ "repositories":
{ "":
{ "repository": {"type": "file", "path": "src"}
- , "bindings": {"rules": "rules/nix"}
+ , "bindings": {"rules": "rules/nix", "rust": "rules-rust/nix"}
}
, "test":
{ "repository": {"type": "file", "path": "test"}
@@ -10,6 +10,11 @@
, "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"
+ }
, "rules/nix-test":
{ "repository": "rules"
, "target_root": "defaults"
@@ -26,5 +31,14 @@
, "subdir": "rules"
}
}
+ , "rules-rust":
+ { "repository":
+ { "type": "git"
+ , "repository": "https://github.com/just-buildsystem/rules-rust"
+ , "branch": "master"
+ , "commit": "bf3e05a614f1de5a9a8a0f8e40f1dd9e1f6609da"
+ , "subdir": "rules"
+ }
+ }
}
}
diff --git a/etc/repos.template.json b/etc/repos.template.json
index bb4d04c..929e149 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"}
+ , "bindings": {"rules": "rules/nix", "rust": "rules-rust/nix"}
}
, "test":
{ "repository": {"type": "file", "path": "test"}
@@ -10,6 +10,11 @@
, "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"
+ }
, "rules/nix-test":
{ "repository": "rules"
, "target_root": "defaults"
diff --git a/nix-dependencies/dependencies.nix b/nix-dependencies/dependencies.nix
index 99280cc..a328ddd 100644
--- a/nix-dependencies/dependencies.nix
+++ b/nix-dependencies/dependencies.nix
@@ -6,6 +6,7 @@
, grpc
, clang
, fmt
+, rustc
# for tests
, gnugrep
@@ -44,6 +45,7 @@ stdenv.mkDerivation rec {
test=$(jo PATH=$(jo -a ${gnugrep}/bin ${unixtools.xxd}/bin)) \
PKGCONFIG=$(jo pkg-config=${pkg-config}/bin/pkg-config \
PKG_CONFIG_PATH=$(jo -a $PKG_CONFIG_PATH)) \
+ RUST=$(jo PATH=$(jo -a ${rustc}/bin ${clang}/bin ${coreutils}/bin /bin)) \
) > config.json
cat config.json
jo "just files"=$(jo config=$(jo -a $(jo root=system path=$out/share/config.json))) > rc.json
diff --git a/src/rust/hello/TARGETS b/src/rust/hello/TARGETS
new file mode 100644
index 0000000..348e7fe
--- /dev/null
+++ b/src/rust/hello/TARGETS
@@ -0,0 +1,6 @@
+{ "":
+ { "type": ["@", "rust", "rust", "binary"]
+ , "name": ["hello"]
+ , "crate_root": ["main.rs"]
+ }
+}
diff --git a/src/rust/hello/main.rs b/src/rust/hello/main.rs
new file mode 100644
index 0000000..21e1c4e
--- /dev/null
+++ b/src/rust/hello/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, World!");
+}
diff --git a/test/TARGETS b/test/TARGETS
index 54f7274..3d3eacd 100644
--- a/test/TARGETS
+++ b/test/TARGETS
@@ -4,6 +4,7 @@
, "dirs":
[ [["./", "hello", ""], "hello"]
, [["./", "proto", ""], "proto"]
+ , [["./", "rust", ""], "rust"]
, [["./", "withExtendedPath", ""], "withExtendedPath"]
]
}
diff --git a/test/rust/TARGETS b/test/rust/TARGETS
new file mode 100644
index 0000000..713ff64
--- /dev/null
+++ b/test/rust/TARGETS
@@ -0,0 +1,8 @@
+{ "":
+ { "type": "install"
+ , "tainted": ["test"]
+ , "dirs":
+ [ [["./", "hello", ""], "hello"]
+ ]
+ }
+}
diff --git a/test/rust/hello/TARGETS b/test/rust/hello/TARGETS
new file mode 100644
index 0000000..ab48819
--- /dev/null
+++ b/test/rust/hello/TARGETS
@@ -0,0 +1,8 @@
+{ "": {"type": "install", "tainted": ["test"], "deps": ["hello"]}
+, "hello":
+ { "type": ["@", "rules", "shell/test", "script"]
+ , "name": ["hello"]
+ , "test": ["test_hello.sh"]
+ , "deps": [["@", "src", "rust/hello", ""]]
+ }
+}
diff --git a/test/rust/hello/test_hello.sh b/test/rust/hello/test_hello.sh
new file mode 100644
index 0000000..531f888
--- /dev/null
+++ b/test/rust/hello/test_hello.sh
@@ -0,0 +1,3 @@
+set -e
+
+./hello | grep -i world