From cc6aac612e36da3c9b9b4e47fc16ed512a79f2d9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Thu, 17 Aug 2023 17:28:03 -0400 Subject: Nixify rust build Not getting deps yet but thats okay, I basically need to do a bunch of annoying nix work to get rustPackages into a thing like pythonPackages. --- Biz/Bild.hs | 35 ++++++++++++++++++++++++----------- Biz/Bild.nix | 3 ++- Biz/Bild/Builder.nix | 20 ++++++++++++++++---- Biz/Namespace.hs | 1 + 4 files changed, 43 insertions(+), 16 deletions(-) (limited to 'Biz') diff --git a/Biz/Bild.hs b/Biz/Bild.hs index a9988d5..81947ed 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -458,7 +458,7 @@ analyze hmap ns = case Map.lookup ns hmap of outPath = outToPath pout, out = pout, srcs = Set.singleton path, - packageSet = "pythonWith", + packageSet = "pythonPackages", .. } |> Just @@ -514,7 +514,7 @@ analyze hmap ns = case Map.lookup ns hmap of { builder = Local user host, wrapper = Nothing, compiler = Ghc, - packageSet = "ghcWith", + packageSet = "ghcPackages", compilerFlags = [ "-Werror", "-threaded", @@ -631,16 +631,28 @@ analyze hmap ns = case Map.lookup ns hmap of |> Just |> pure Namespace.Rs -> - Meta.detectOut (Meta.out "//") contentLines |> \out -> + Meta.detectAll "//" contentLines |> \Meta.Parsed {..} -> Target - { langdeps = Set.empty, + { langdeps = pdep, + -- this packageSet doesn't actually exist because everyone in + -- nix just generates nix expressions for rust dependencies with + -- Cargo.lock, so I have to make it in order to use rust deps packageSet = "rustPackages", wrapper = Nothing, - sysdeps = Set.empty, + sysdeps = psys <> Set.singleton "rustc", + out = pout, compiler = Rustc, - compilerFlags = map Text.pack [absPath, "-o", root outToPath out], + compilerFlags = case pout of + Meta.Bin o -> + map + Text.pack + [ "$BIZ_ROOT" path, + "-o", + o + ] + _ -> panic "can't build rust libs", builder = Local user host, - outPath = outToPath out, + outPath = outToPath pout, srcs = Set.singleton absPath, .. } @@ -776,9 +788,9 @@ build andTest loud analysis = Copy -> do Log.warn ["bild", "copy", "not implemented yet", nschunk namespace] pure (Exit.ExitSuccess, mempty) - Rustc -> do + Rustc -> Log.info ["bild", "dev", "rust", nschunk namespace] - proc loud namespace (toNixFlag compiler) compilerFlags + >> nixBuild loud target Sbcl -> do Log.info ["bild", "dev", "lisp", nschunk namespace] proc loud namespace (toNixFlag compiler) compilerFlags @@ -962,6 +974,7 @@ nixBuild loud Target {..} = selectBuilder :: Namespace -> Text selectBuilder = \case - Namespace _ Namespace.Hs -> "base" + Namespace _ Namespace.Hs -> "haskell" Namespace _ Namespace.Py -> "python" - _ -> panic "no builder for this namespace" + Namespace _ Namespace.Rs -> "base" + Namespace _ ext -> panic <| "no builder for " <> show ext diff --git a/Biz/Bild.nix b/Biz/Bild.nix index 918d6b1..94305bc 100644 --- a/Biz/Bild.nix +++ b/Biz/Bild.nix @@ -22,10 +22,12 @@ rec { haskellDeps = import ./Bild/Deps/Haskell.nix; + ghcPackages = nixpkgs.haskellPackages; ghcWith = nixpkgs.haskell.packages.${constants.ghcCompiler}.ghcWithHoogle; sbclWith = nixpkgs.lispPackages_new.sbclWithPackages; + pythonPackages = nixpkgs.python3Packages; pythonWith = nixpkgs.python3.withPackages; ghcPackageSetFull = private.ghcWith private.haskellDeps; @@ -51,7 +53,6 @@ rec { (private.ghcWith (hpkgs: with hpkgs; [])) /* disable until nixified builds are complete */ - rustc # c deps gcc gdb valgrind argp-standalone SDL # lisp deps diff --git a/Biz/Bild/Builder.nix b/Biz/Bild/Builder.nix index 2b1403a..7ce29a2 100644 --- a/Biz/Bild/Builder.nix +++ b/Biz/Bild/Builder.nix @@ -34,11 +34,11 @@ let src = lib.sources.cleanSourceWith {inherit filter; src = lib.sources.cleanSource root;}; - langdeps_ = pkgset: + langdeps_ = if langdeps == null || langdeps == [] then [] else - private.selectAttrs (lib.strings.splitString " " langdeps) pkgset; + private.selectAttrs (lib.strings.splitString " " langdeps) private.${packageSet}; sysdeps_ = if sysdeps == null || sysdeps == [] then [] @@ -48,14 +48,26 @@ let in { base = stdenv.mkDerivation rec { inherit name src BIZ_ROOT postUnpack; - buildInputs = [ (private.${packageSet} langdeps_) ] ++ sysdeps_; + buildInputs = langdeps_ ++ sysdeps_; + installPhase = "install -D ${name} $out/bin/${name}"; + buildPhase = compileLine; + }; + + + haskell = stdenv.mkDerivation rec { + inherit name src BIZ_ROOT postUnpack; + buildInputs = sysdeps_ ++ [ + (private.ghcWith (p: + (private.selectAttrs (lib.strings.splitString " " langdeps) p) + )) + ]; installPhase = "install -D ${name} $out/bin/${name}"; buildPhase = compileLine; }; python = buildPythonApplication rec { inherit name src BIZ_ROOT postUnpack; - propagatedBuildInputs = [ (private.${packageSet} langdeps_) ] ++ sysdeps_; + propagatedBuildInputs = [ (private.pythonWith (_: langdeps_)) ] ++ sysdeps_; buildInputs = sysdeps_; checkInputs = [(private.pythonWith (p: with p; [black mypy pylint]))]; checkPhase = '' diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs index 8cc6b5c..c811554 100644 --- a/Biz/Namespace.hs +++ b/Biz/Namespace.hs @@ -90,6 +90,7 @@ toModule :: Namespace -> String toModule (Namespace parts Hs) = joinWith "." parts toModule (Namespace parts Py) = joinWith "." parts toModule (Namespace parts Scm) = "(" ++ joinWith " " parts ++ ")" +toModule (Namespace parts Rs) = joinWith "::" parts toModule (Namespace {..}) = panic <| "toModule not implemented for " <> show ext toHaskellModule :: Namespace -> String -- cgit v1.2.3