diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-06-26 09:00:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-26 09:00:43 +0200 |
commit | 7dc9a7b9107b2607e9870d7fc92fb2d40505f7ef (patch) | |
tree | 3b1bfe9958b324b5bd0768b48bfa76aaaa3eecc7 | |
parent | afcdb1184799526f20954e475af990254d772cd4 (diff) | |
parent | e65cf1d265210738a9b3c0b811fbfeffa0741c39 (diff) | |
download | hello-nix-7dc9a7b9107b2607e9870d7fc92fb2d40505f7ef.tar.gz |
Merge pull request #2 from aehlig/import-rules
Import rust rules and add a minimal example
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | etc/defaults/rust/TARGETS | 43 | ||||
-rwxr-xr-x | etc/generate-repos.sh | 15 | ||||
-rw-r--r-- | etc/repos.json | 34 | ||||
-rw-r--r-- | etc/repos.template.json | 26 | ||||
-rw-r--r-- | nix-dependencies/dependencies.nix | 2 | ||||
-rw-r--r-- | nix-import-tools/default.nix | 2 | ||||
-rw-r--r-- | nix-import-tools/import-tools.nix | 41 | ||||
-rw-r--r-- | shell.nix | 2 | ||||
-rw-r--r-- | src/rust/hello/TARGETS | 6 | ||||
-rw-r--r-- | src/rust/hello/main.rs | 3 | ||||
-rw-r--r-- | test/TARGETS | 1 | ||||
-rw-r--r-- | test/rust/TARGETS | 8 | ||||
-rw-r--r-- | test/rust/hello/TARGETS | 8 | ||||
-rw-r--r-- | test/rust/hello/test_hello.sh | 3 | ||||
-rwxr-xr-x | update-just-dependencies.sh | 1 |
16 files changed, 189 insertions, 17 deletions
@@ -112,13 +112,10 @@ There are two files pinning dependencies be updated using [update-nix-dependencies.sh](./update-nix-dependencies.sh) which simply calls `niv update` in our `nix-shell`. - The dependencies on other other justbuild projects are - pinned in [etc/repos.json](etc/repos.json). As, at the - moment, there is only one external justbuild dependency, - the [rules-cc](https://github.com/just-buildsystem/rules-cc), - this is updated by hand. For larger - projects [just-import-git](https://github.com/just-buildsystem/justbuild/blob/master/share/man/just-import-git.1.md) - would be used to generate this file out of a description of the - local repositories and the dependencies to import. + pinned in [etc/repos.json](etc/repos.json). They can be updated using + [update-just-dependencies.sh](./update-just-dependencies.sh) which + calls [etc/generate-repos.sh](./etc/generate-repos.sh) in our `nix-shell`, + which also brings in tools required for this step. ### Logical repositories 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 new file mode 100755 index 0000000..8bd1ca6 --- /dev/null +++ b/etc/generate-repos.sh @@ -0,0 +1,15 @@ +#!/bin/sh + + +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 d1537db..1f68227 100644 --- a/etc/repos.json +++ b/etc/repos.json @@ -1,24 +1,20 @@ { "repositories": { "": { "repository": {"type": "file", "path": "src"} - , "bindings": {"rules": "rules/nix"} + , "bindings": {"rules": "rules/nix", "rust": "rules-rust/nix"} } , "test": { "repository": {"type": "file", "path": "test"} , "bindings": {"rules": "rules/nix-test", "src": ""} } , "defaults": {"repository": {"type": "file", "path": "etc/defaults"}} - , "rules": - { "repository": - { "type": "git" - , "branch": "master" - , "commit": "0d436f26134d3fcaa695e4e6e87249d7fa381e44" - , "repository": "https://github.com/just-buildsystem/rules-cc.git" - , "subdir": "rules" - } - } , "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 +22,23 @@ , "target_file_name": "test.TARGETS" , "bindings": {"base": "rules/nix"} } + , "rules": + { "repository": + { "type": "git" + , "repository": "https://github.com/just-buildsystem/rules-cc" + , "branch": "master" + , "commit": "0e9d13a761c878a647fde5a543946a02bf2c693d" + , "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 new file mode 100644 index 0000000..929e149 --- /dev/null +++ b/etc/repos.template.json @@ -0,0 +1,26 @@ +{ "repositories": + { "": + { "repository": {"type": "file", "path": "src"} + , "bindings": {"rules": "rules/nix", "rust": "rules-rust/nix"} + } + , "test": + { "repository": {"type": "file", "path": "test"} + , "bindings": {"rules": "rules/nix-test", "src": ""} + } + , "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" + , "rule_root": "rules" + , "target_file_name": "test.TARGETS" + , "bindings": {"base": "rules/nix"} + } + } +} 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/nix-import-tools/default.nix b/nix-import-tools/default.nix new file mode 100644 index 0000000..e8f8026 --- /dev/null +++ b/nix-import-tools/default.nix @@ -0,0 +1,2 @@ +{ nixpkgs ? import <nixpkgs> {} }: +nixpkgs.callPackage ./import-tools.nix {} diff --git a/nix-import-tools/import-tools.nix b/nix-import-tools/import-tools.nix new file mode 100644 index 0000000..cfb7a91 --- /dev/null +++ b/nix-import-tools/import-tools.nix @@ -0,0 +1,41 @@ +{ stdenv +, fetchFromGitHub +, python3 +}: + +stdenv.mkDerivation rec { + name = "just-import-tools"; + version = "2024-06-25"; + + buildInputs = [ (python3.withPackages (ps: [])) ]; + + srcjust = fetchFromGitHub { + owner = "just-buildsystem"; + repo = "justbuild"; + rev = "v1.3.1"; + sha256 = "sha256-kv7HpDEYZml5uk06s8Cxt5rEpxaJBz9s+or6Od1q4Io="; + }; + + srcrustrules = fetchFromGitHub { + owner = "just-buildsystem"; + repo = "rules-rust"; + rev = "bf3e05a614f1de5a9a8a0f8e40f1dd9e1f6609da"; + sha256 = "sha256-8y10ZmZpeTGtbkIeneaVISyMbVKfIi3gHqyvztnKn0M="; + }; + + + unpackPhase = '' + cp $srcjust/bin/just-import-git.py . + cp $srcrustrules/bin/hdump.py . + ''; + + dontBuild = true; + + installPhase = '' + mkdir -p $out/bin + cp just-import-git.py $out/bin/just-import-git + cp hdump.py $out/bin/hdump + chmod 555 $out/bin/just-import-git $out/bin/hdump + ''; + +} @@ -7,6 +7,7 @@ let pkgs = import nixpkgs {}; nix-dependencies = import ./nix-dependencies { nixpkgs = pkgs; } ; + update-deps = import ./nix-import-tools { nixpkgs = pkgs; } ; in pkgs.mkShell rec { @@ -14,6 +15,7 @@ in pkgs.mkShell rec { buildInputs = with pkgs; [ niv + update-deps ]; shellHook = '' 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 diff --git a/update-just-dependencies.sh b/update-just-dependencies.sh new file mode 100755 index 0000000..e9469d3 --- /dev/null +++ b/update-just-dependencies.sh @@ -0,0 +1 @@ +nix-shell --run "./etc/generate-repos.sh" |