diff --git a/.gitignore b/.gitignore index fcfc4a1..53ba2fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ result* +result-* +*~ +.DS_Store diff --git a/README.md b/README.md index 11201aa..d25eca8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ -# rust-for-linux/nix +# Rust for Linux Nix Efforts for packaging the Rust for Linux project with the [Nix package manager](https://nixos.org/). - -``` -$ nix-build -A kernel -``` diff --git a/default.nix b/default.nix deleted file mode 100644 index c63320e..0000000 --- a/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ sources ? import nix/sources.nix -, nixpkgs ? sources.nixpkgs -, linux ? sources.linux -, system ? builtins.currentSystem -}: - -let - pkgs = import nixpkgs { inherit system; }; - - rust-for-linux = let - version = "5.16"; - modVersion = "5.16.0"; - src = linux; - - kernel = pkgs.callPackage ./packages/kernel.nix { - inherit version modVersion src; - }; - in { - doc = pkgs.callPackage ./packages/rustdoc.nix { - inherit version src; - inherit (kernel) configfile; - }; - htmldoc = pkgs.callPackage ./packages/htmldoc.nix { - inherit version src; - inherit (kernel) configfile; - }; - - inherit kernel; - # TODO: expose configfile somewhere - - tests = import ./tests { inherit nixpkgs kernel pkgs; }; - }; - -in - rust-for-linux diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..89d3237 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1739866667, + "narHash": "sha256-EO1ygNKZlsAC9avfcwHkKGMsmipUk1Uc0TbrEZpkn64=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "73cf49b8ad837ade2de76f87eb53fc85ed5d4680", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1736320768, + "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "oxalica": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1740074384, + "narHash": "sha256-T2eO9ognlph94/TyAu1uILo38fZG1G4S5FQxG+YBDv0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "d291a120b6524911249b198baf3ec3e07ff57e04", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "oxalica": "oxalica" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..645c739 --- /dev/null +++ b/flake.nix @@ -0,0 +1,22 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + oxalica.url = "github:oxalica/rust-overlay"; + }; + + outputs = inputs@{ self, nixpkgs, flake-utils, ... }: { + } // flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ inputs.oxalica.overlays.default ]; + }; + in { + devShells = { + default = pkgs.callPackage ./nix/shell.nix { rustAttrs = pkgs.rust-bin.stable.latest; llvmPackages = pkgs.llvmPackages_18; }; + clang = self.devShells.${system}.default.override { isClang = true; }; + }; + }); +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..d1d5afe --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,109 @@ +{ lib +, mkShellNoCC +, writeShellScriptBin + +, b4 + +, gnumake +, pkg-config +, ncurses +, rustAttrs +, rust-bindgen-unwrapped + +, elfutils +, bison +, flex +, perl +, bc +, nettools +, openssl +, rsync +, gmp +, libmpc +, mpfr +, zstd +, python3Minimal +, kmod +, hexdump + +, isClang ? false +, llvmPackages +, gcc ? null +}: + +#assert !isClang -> gcc; + +let + makeBinArg = package: name: bin: "${name}=${package}/bin/${bin}"; + makeHostToolArg = package: unwrapped: name: bin: "${makeBinArg unwrapped name bin} ${makeBinArg package "HOST${name}" bin}"; + makeMakeVars = vars: lib.concatStringsSep " \\\n " ((map (v: + if v ? package-unwrapped then + makeHostToolArg v.package v.package-unwrapped v.name v.bin + else + makeBinArg v.package v.name v.bin)) vars); + clangTool = { name, bin, hostPackage ? "clang", package ? "${hostPackage}-unwrapped" }: [ + { inherit name; value = "${llvmPackages.${package}}/bin/${bin}"; } + { name = "HOST${name}"; value = "${llvmPackages.${hostPackage}}/bin/${bin}"; } + ]; + + # Env variables that make wants + makeEnv = if isClang then ({ + LLVM = "1"; + NM = "${llvmPackages.libllvm}/bin/llvm-nm"; + STRIP = "${llvmPackages.libllvm}/bin/llvm-strip"; + OBJCOPY = "${llvmPackages.libllvm}/bin/llvm-objcopy"; + READELF = "${llvmPackages.libllvm}/bin/llvm-readelf"; + LLVM_AS = "${llvmPackages.libllvm}/bin/llvm-as"; + LLVM_LINK = "${llvmPackages.libllvm}/bin/llvm-link"; + KCFLAGS = "\"-isystem ${llvmPackages.clang}/resource-root/include\""; + } // (lib.listToAttrs (lib.flatten (map clangTool [ + { name = "CC"; bin = "clang"; } + { name = "LD"; bin = "ld.lld"; hostPackage = "bintools"; } + { name = "AR"; bin = "ar"; hostPackage = "bintools"; } + ])))) else { + TODO = builtins.warn "TODO gcc build"; + }; + + gnumake' = writeShellScriptBin "make" '' + ${gnumake}/bin/make "$@" \ + ${lib.concatStringsSep " \\\n " (lib.mapAttrsToList (name: value: "${name}=${value}") makeEnv)} + ''; +in mkShellNoCC { + name = "linux"; + + packages = [ + b4 + + gnumake' + pkg-config + ncurses + + elfutils + bison + flex + perl + bc + nettools + openssl + rsync + gmp + libmpc + mpfr + zstd + python3Minimal + kmod + hexdump + + (rustAttrs.default.override { + extensions = [ "rust-src" "rust-analyzer" ]; + }) + rust-bindgen-unwrapped + ]; + + env = makeEnv; + + LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; + + hardeningDisable = + [ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ]; +} diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index dca3327..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "linux": { - "branch": "rust", - "description": "Adding support for the Rust language to the Linux kernel.", - "homepage": "", - "owner": "rust-for-linux", - "repo": "linux", - "rev": "be91a559939339c61c1eefafa359cbd280a59588", - "sha256": "0ic2gv75axql8mbzcls7lx4gs5gnksjvg3ik67knvbf18jr6ynf6", - "type": "tarball", - "url": "https://github.com/rust-for-linux/linux/archive/be91a559939339c61c1eefafa359cbd280a59588.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", - "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs": { - "branch": "staging-next", - "description": "Nix Packages collection", - "homepage": "", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "fd0f3770487195701352ce16c3d816576125df84", - "sha256": "0lg82ijnwbhxl3nrhfcdc8ygdmidj6bymalw616jf4k0q3bv8154", - "type": "tarball", - "url": "https://github.com/nixos/nixpkgs/archive/fd0f3770487195701352ce16c3d816576125df84.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 1938409..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,174 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/packages/htmldoc.nix b/packages/htmldoc.nix deleted file mode 100644 index 17bcf0a..0000000 --- a/packages/htmldoc.nix +++ /dev/null @@ -1,129 +0,0 @@ -{ lib, src, configfile, version, stdenv, rustPlatform, rustfmt, rust-bindgen - -, perl, bc, nettools, openssl, rsync, gmp, libmpc, mpfr, gawk, zstd -, python3Minimal, libelf, bison, flex, cpio, elfutils, buildPackages - -, sphinx, python39Packages -, imagemagick, graphviz, librsvg -, texlive -, which -}: - -let - inherit (rustPlatform.rust) rustc; - - tex = texlive.combine { - inherit (texlive) scheme-small; - inherit (texlive) latexmk anyfontsize capt-of; - inherit (texlive) eqparbox fncychap framed; - inherit (texlive) luatex85 multirow needspace; - inherit (texlive) tabulary threeparttable titlesec; - inherit (texlive) ucs wrapfig; - }; - -in stdenv.mkDerivation { - pname = "linux-htmldoc"; - inherit version src; - - depsBuildBuild = [ buildPackages.stdenv.cc ]; - nativeBuildInputs = [ - perl - bc - nettools - openssl - rsync - gmp - libmpc - mpfr - gawk - zstd - python3Minimal - libelf - bison - flex - cpio - elfutils - rustc - rust-bindgen - rustfmt - - # documentation - sphinx python39Packages.sphinx_rtd_theme - imagemagick graphviz librsvg - tex which - ]; - hardeningDisable = - [ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ]; - - RUST_LIB_SRC = rustPlatform.rustLibSrc; - - #enableParallelBuilding = true; - - prePatch = '' - for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); do - echo "stripping FHS paths in \`$mf'..." - sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g' - done - sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|' - - # Don't include a (random) NT_GNU_BUILD_ID, to make the build more deterministic. - # This way kernels can be bit-by-bit reproducible depending on settings - # (e.g. MODULE_SIG and SECURITY_LOCKDOWN_LSM need to be disabled). - # See also https://kernelnewbies.org/BuildId - sed -i Makefile -e 's|--build-id=[^ ]*|--build-id=none|' - - patchShebangs scripts - patchShebangs Documentation - ''; - - configurePhase = '' - runHook preConfigure - - - mkdir build - export buildRoot="$(pwd)/build" - - echo "manual-config configurePhase buildRoot=$buildRoot pwd=$PWD" - - if [ -f "$buildRoot/.config" ]; then - echo "Could not link $buildRoot/.config : file exists" - exit 1 - fi - ln -sv ${configfile} $buildRoot/.config - - runHook postConfigure - - # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged. - buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)") - - #cd $buildRoot - ''; - - buildFlags = [ - "KBUILD_BUILD_VERSION=1-NixOS" - "SPHINXBUILD=${sphinx}/bin/sphinx-build" - "htmldocs" - "O=build" - ]; - - preInstall = '' - installFlagsArray+=("-j$NIX_BUILD_CORES") - ''; - - installPhase = '' - mkdir "$out" - cp -r build/Documentation/output/* "$out/" - mkdir -p $out/nix-support - echo "doc manual $out/" >> $out/nix-support/hydra-build-products - ''; - - meta = { - description = "The Linux kernel html documentation"; - license = lib.licenses.gpl2Only; - homepage = "https://github.com/rust-for-linux/linux"; - repositories.git = "https://github.com/rust-for-linux/linux"; - maintainers = [ lib.maintainers.kloenk ]; - platforms = lib.platforms.linux; - timeout = 14400; # 4 hours - }; -} diff --git a/packages/kernel.nix b/packages/kernel.nix deleted file mode 100644 index 397a4f4..0000000 --- a/packages/kernel.nix +++ /dev/null @@ -1,68 +0,0 @@ -{ lib, stdenv, llvmPackages_latest, rustPlatform, rustfmt, rust-bindgen -, buildLinux, linuxManualConfig, kernelPatches - -, src, version, modVersion ? null, features ? null, ... }@args: - -let - llvmPackages = llvmPackages_latest; - inherit (llvmPackages_latest) clang; - - inherit (rustPlatform.rust) rustc; - - addRust = old: { - ignoreConfigErrors = true; - - RUST_LIB_SRC = rustPlatform.rustLibSrc; - buildInputs = (old.buildInputs or [ ]) ++ [ rustc ]; - nativeBuildInputs = (old.nativeBuildInputs or [ ]) - ++ [ rust-bindgen rustfmt ]; - }; - -in (linuxManualConfig rec { - inherit src version stdenv lib; - - kernelPatches = with args.kernelPatches; [ - #bridge_stp_helper - #request_key_helper - ]; - - # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if modVersion != null then - modVersion - else - with lib; concatStringsSep "." (take 3 (splitVersion "${version}.0")); - - # branchVersion needs to be x.y - extraMeta = { branch = lib.versions.majorMinor version; }; - - randstructSeed = ""; - - configfile = (buildLinux { - inherit src version stdenv modDirVersion kernelPatches extraMeta; - - structuredExtraConfig = with lib.kernel; { - RUST = yes; - SAMPLES = yes; - SAMPLES_RUST = yes; - SAMPLE_RUST_MINIMAL = module; - SAMPLE_RUST_PRINT = module; - SAMPLE_RUST_MODULE_PARAMETERS = module; - SAMPLE_RUST_SYNC = module; - SAMPLE_RUST_CHRDEV = module; - SAMPLE_RUST_MISCDEV = module; - SAMPLE_RUST_STACK_PROBING = module; - SAMPLE_RUST_SEMAPHORE = module; - SAMPLE_RUST_SEMAPHORE_C = module; - - }; - }).configfile.overrideAttrs addRust; - - config = { - #CONFIG_MODULES = "y"; - #CONFIG_FW_LOADER = "m"; - - # needed to get the vm test working. whatever. - isEnabled = f: true; - isYes = f: true; - }; -}).overrideAttrs addRust diff --git a/packages/rustdoc.nix b/packages/rustdoc.nix deleted file mode 100644 index a0211bf..0000000 --- a/packages/rustdoc.nix +++ /dev/null @@ -1,104 +0,0 @@ -{ lib, src, configfile, version, stdenv, rustPlatform, rustfmt, rust-bindgen - -, perl, bc, nettools, openssl, rsync, gmp, libmpc, mpfr, gawk, zstd -, python3Minimal, libelf, bison, flex, cpio, elfutils, buildPackages }: - -let inherit (rustPlatform.rust) rustc; - -in stdenv.mkDerivation { - pname = "linux-doc"; - inherit version src; - - depsBuildBuild = [ buildPackages.stdenv.cc ]; - nativeBuildInputs = [ - perl - bc - nettools - openssl - rsync - gmp - libmpc - mpfr - gawk - zstd - python3Minimal - libelf - bison - flex - cpio - elfutils - rustc - rust-bindgen - rustfmt - ]; - hardeningDisable = - [ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ]; - - RUST_LIB_SRC = rustPlatform.rustLibSrc; - - #enableParallelBuilding = true; - - configurePhase = '' - runHook preConfigure - - - mkdir build - export buildRoot="$(pwd)/build" - - echo "manual-config configurePhase buildRoot=$buildRoot pwd=$PWD" - - if [ -f "$buildRoot/.config" ]; then - echo "Could not link $buildRoot/.config : file exists" - exit 1 - fi - ln -sv ${configfile} $buildRoot/.config - - runHook postConfigure - - # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged. - buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)") - - #cd $buildRoot - ''; - - buildFlags = [ "KBUILD_BUILD_VERSION=1-NixOS" "rustdoc" "O=build" ]; - - preInstall = '' - installFlagsArray+=("-j$NIX_BUILD_CORES") - ''; - - installPhase = '' - mkdir "$out" - cp -r build/rust/doc/* "$out/" - mkdir -p $out/nix-support - echo "doc manual $out/" >> $out/nix-support/hydra-build-products - - cat < $out/index.html - - - - - Rust for Linux documentation (Hydra) - - - - - - -

Redirecting...

- Click here if you are not redirected. - - - EOF - ''; - - meta = { - description = "The Linux kernel rust documentation"; - license = lib.licenses.gpl2Only; - homepage = "https://github.com/rust-for-linux/linux"; - repositories.git = "https://github.com/rust-for-linux/linux"; - maintainers = [ lib.maintainers.kloenk ]; - platforms = lib.platforms.linux; - timeout = 14400; # 4 hours - }; -} diff --git a/tests/default.nix b/tests/default.nix deleted file mode 100644 index 060348c..0000000 --- a/tests/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - kernel -, nixpkgs -, pkgs -, system ? builtins.currentSystem -}: - -let - linuxPackages_rust = pkgs.linuxPackagesFor kernel; -in { - minimal = import ./minimal.nix { inherit nixpkgs system linuxPackages_rust; }; - samples = import ./samples.nix { inherit nixpkgs system linuxPackages_rust; }; -} diff --git a/tests/minimal.nix b/tests/minimal.nix deleted file mode 100644 index 56789b0..0000000 --- a/tests/minimal.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ - nixpkgs, system -, linuxPackages_rust -}: - -import "${nixpkgs}/nixos/tests/make-test-python.nix" ({ pkgs, ... }: { - name = "rust-minimal"; - inherit system; - - nodes.machine = { config, pkgs, ... }: { - virtualisation.graphics = false; - - boot.kernelPackages = linuxPackages_rust; - }; - - testScript = '' - start_all() - - machine.wait_for_unit("multi-user.target") - - machine.succeed("modprobe rust_minimal") - machine.wait_for_console_text("Rust minimal sample") - ''; -}) \ No newline at end of file diff --git a/tests/samples.nix b/tests/samples.nix deleted file mode 100644 index 8bdf5db..0000000 --- a/tests/samples.nix +++ /dev/null @@ -1,102 +0,0 @@ -{ - nixpkgs, system -, linuxPackages_rust -}: - -import "${nixpkgs}/nixos/tests/make-test-python.nix" ({ pkgs, ... }: { - name = "rust-samples"; - inherit system; - - nodes.machine = { config, pkgs, ... }: { - virtualisation.graphics = false; - - boot.kernelPackages = linuxPackages_rust; - }; - - testScript = '' - start_all() - - machine.wait_for_unit("multi-user.target") - - # rust_chrdev - machine.succeed("modprobe rust_chrdev") - machine.wait_for_console_text("Rust character device sample \(init\)") - # TODO: use chardev - machine.succeed("rmmod rust_chrdev") - machine.wait_for_console_text("Rust character device sample \(exit\)") - - # rust_minimal - machine.succeed("modprobe rust_minimal") - machine.wait_for_console_text("Rust minimal sample \(init\)") - machine.wait_for_console_text("Am I built-in?") - machine.succeed("rmmod rust_minimal") - machine.wait_for_console_text("My message is on the heap!") - machine.wait_for_console_text("Rust minimal sample \(exit\)") - - # rust_miscdev - machine.succeed("modprobe rust_miscdev") - machine.wait_for_console_text("Rust miscellaneous device sample \(init\)") - machine.succeed("echo test > /dev/rust_miscdev &") - machine.log("testing if /dev/rust_miscdev does contain '\0x1'") - assert machine.succeed("cat /dev/rust_miscdev"), '\0x1' - machine.succeed("rmmod rust_miscdev") - machine.wait_for_console_text("Rust miscellaneous device sample \(exit\)") - - # rust_module_parameters - machine.succeed("modprobe rust_module_parameters") - machine.wait_for_console_text("Rust module parameters sample \(init\)") - machine.wait_for_console_text("Parameters") - machine.wait_for_console_text("my_bool:\s*true") - machine.wait_for_console_text("my_i32:\s*42") - machine.wait_for_console_text("my_str:\s*default str val") - machine.wait_for_console_text("my_usize:\s*42") - machine.wait_for_console_text("my_array:\s*\[0, 1\]") - # todo: tests - machine.succeed("rmmod rust_module_parameters") - machine.wait_for_console_text("Rust module parameters sample \(exit\)") - - # rust_print - machine.succeed("modprobe rust_print") - machine.wait_for_console_text("Rust printing macros sample \(init\)") - machine.wait_for_console_text("Emergency message \(level 0\) without args") - machine.wait_for_console_text("Alert message \(level 1\) without args") - machine.wait_for_console_text("Critical message \(level 2\) without args") - machine.wait_for_console_text("Error message \(level 3\) without args") - machine.wait_for_console_text("Warning message \(level 4\) without args") - machine.wait_for_console_text("Notice message \(level 5\) without args") - machine.wait_for_console_text("Info message \(level 6\) without args") - machine.wait_for_console_text("A line that is continued without args") - machine.wait_for_console_text("Emergency message \(level 0\) with args") - machine.wait_for_console_text("Alert message \(level 1\) with args") - machine.wait_for_console_text("Critical message \(level 2\) with args") - machine.wait_for_console_text("Error message \(level 3\) with args") - machine.wait_for_console_text("Warning message \(level 4\) with args") - machine.wait_for_console_text("Notice message \(level 5\) with args") - machine.wait_for_console_text("Info message \(level 6\) with args") - machine.wait_for_console_text("A line that is continued with args") - machine.succeed("rmmod rust_print") - machine.wait_for_console_text("Rust printing macros sample \(exit\)") - - machine.succeed("modprobe rust_random") - machine.wait_for_file("/dev/rust_random") - machine.succeed("rmmod rust_random") - - machine.succeed("modprobe rust_semaphore") - machine.wait_for_console_text("Rust semaphore sample \(init\)") - machine.succeed("rmmod rust_semaphore") - machine.wait_for_console_text("Rust semaphore sample \(exit\)") - - machine.succeed("modprobe rust_stack_probing") - machine.wait_for_console_text("Rust stack probing sample \(init\)") - machine.wait_for_console_text("arge array has length:") - machine.succeed("rmmod rust_stack_probing") - machine.wait_for_console_text("Rust stack probing sample \(exit\)") - - machine.succeed("modprobe rust_sync") - machine.wait_for_console_text("Rust synchronisation primitives sample \(init\)") - machine.wait_for_console_text("Value: 10") - machine.wait_for_console_text("Value: 10") - machine.succeed("rmmod rust_sync") - machine.wait_for_console_text("Rust synchronisation primitives sample \(exit\)") - ''; -}) \ No newline at end of file