Skip to content

Commit 7e55861

Browse files
committed
Add support for Rust projects
1 parent ac27be9 commit 7e55861

33 files changed

+815
-112
lines changed

.last-exported-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Last exported commit from parent repo: 184e5869a6f7c79f4adaca446e08f30371aa3946
1+
Last exported commit from parent repo: 4e3a180f6244a837354c81dfa84e62387c415233

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,32 @@ The following symbols are used throughout this page to indicate support status:
3333

3434
### Toolchain Support
3535

36-
| Toolchain\\\\Feature | Development Environment | VSCode DevContainer | Gitignore | Pre-Commit Hooks<sup>[1](#footnote1)</sup> | Reproducible Production Builds |
37-
| :----------------------------------------: | :-------------------------------------------------------------------------: | :-----------------------------------------------------------------------------: | :-------: | :----------------------------------------: | :---------------------------------------------------------------------------------------: |
38-
| Elm | ✅ <br>Either as a standalone app or as part of a Node project with Parcel. | ✅ <br>With the Elm extension installed. ||||
39-
| Golang || ✅ <br>With the official Go extension installed. ||| 🟠 <br>Support is currently considered _experimental_. |
40-
| Haskell | ✅ <br>Either as a simple project or just a place to run a repl. | ✅ <br>With the haskell.haskell extension installed. ||| 🕓 |
41-
| Java | ✅ <br>With maven, google-java-format, and optionally minishift. | ✅ <br>With the official Java, and optionally the Lombok, extensions installed. ||| 🟠 <br>Only supports Spring applications. Support is currently considered _experimental_. |
42-
| Minimal (With no project-specific tooling) |||| 🟠 ||
43-
| NodeJS | ✅ <br>With latest stable node, AWS CLI, and optionally PNPm/Yarn. |||||
44-
| Python | ✅ <br>With Python version 3.9 | ✅ <br>With the official Python VSCode extension. || 🟠 ||
36+
| Toolchain\\\\Feature | Development Environment | VSCode DevContainer | Gitignore | Pre-Commit Hooks[1](#footnote1) | Reproducible Production Builds |
37+
| :----------------------------------------: | :-------------------------------------------------------------------------: | :-----------------------------------------------------------------------------: | :-------: | :-----------------------------: | :---------------------------------------------------------------------------------------: |
38+
| Elm | ✅ <br>Either as a standalone app or as part of a Node project with Parcel. | ✅ <br>With the Elm extension installed. ||||
39+
| Golang || ✅ <br>With the official Go extension installed. ||| 🟠 <br>Support is currently considered _experimental_. |
40+
| Haskell | ✅ <br>Either as a simple project or just a place to run a repl. | ✅ <br>With the haskell.haskell extension installed. ||| 🕓 |
41+
| Java | ✅ <br>With maven, google-java-format, and optionally minishift. | ✅ <br>With the official Java, and optionally the Lombok, extensions installed. ||| 🟠 <br>Only supports Spring applications. Support is currently considered _experimental_. |
42+
| Minimal (With no project-specific tooling) |||| 🟠 ||
43+
| NodeJS | ✅ <br>With latest stable node, AWS CLI, and optionally PNPm/Yarn. |||||
44+
| Python | ✅ <br>With Python version 3.9 | ✅ <br>With the official Python VSCode extension. || 🟠 ||
45+
| Rust || ✅ <br>With the official rust-analyzer extension. ||||
4546

4647
<a id="footnote1"><sup>1</sup></a> Marked as fully supported if any non-nix pre-commit hooks are added.
4748
See the Pre-Commit Hooks table below for details.
4849

4950
### Pre-Commit Hooks
5051

51-
| Toolchain\\\\Hook Type | Nix Formatting[2](#footnote2) | Formatters | Linters | Testing |
52-
| :--------------------: | :---------------------------: | :-----------------------: | :---------------: | :------------: |
53-
| Elm || ✅ <br>elm-format | ✅ <br>elm-review ||
54-
| Golang || ✅ <br>go-fmt || ✅ <br>go test |
55-
| Haskell || ✅ <br>ormolu | ✅ <br>hlint ||
56-
| Java || ✅ <br>google-java-format |||
57-
| Minimal |||||
58-
| NodeJS || ✅ <br>prettier |||
59-
| Python |||||
52+
| Toolchain\\\\Hook Type | Nix Formatting[2](#footnote2) | Formatters | Linters | Testing |
53+
| :--------------------: | :---------------------------: | :-----------------------: | :------------------------: | :------------: |
54+
| Elm || ✅ <br>elm-format | ✅ <br>elm-review ||
55+
| Golang || ✅ <br>go-fmt || ✅ <br>go test |
56+
| Haskell || ✅ <br>ormolu | ✅ <br>hlint ||
57+
| Java || ✅ <br>google-java-format |||
58+
| Minimal |||||
59+
| NodeJS || ✅ <br>prettier |||
60+
| Python |||||
61+
| Rust || ✅<br>rustfmt | ✅<br>cargo check + clippy ||
6062

6163
<a id="footnote2"><sup>2</sup></a> [`alejandra`](https://github.com/kamadorueda/alejandra) is set up to format nix files.
6264

nix-bootstrap.cabal

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 2.0
55
-- see: https://github.com/sol/hpack
66

77
name: nix-bootstrap
8-
version: 1.4.1.0
8+
version: 1.5.0.0
99
author: gchquser
1010
maintainer: [email protected]
1111
copyright: Crown Copyright
@@ -49,6 +49,9 @@ library
4949
Bootstrap.Data.Bootstrappable.NixShellCompat
5050
Bootstrap.Data.Bootstrappable.Python.Requirements
5151
Bootstrap.Data.Bootstrappable.Readme
52+
Bootstrap.Data.Bootstrappable.Rust.CargoLock
53+
Bootstrap.Data.Bootstrappable.Rust.CargoToml
54+
Bootstrap.Data.Bootstrappable.Rust.MainRs
5255
Bootstrap.Data.Bootstrappable.VSCodeExtensions
5356
Bootstrap.Data.Bootstrappable.VSCodeSettings
5457
Bootstrap.Data.BuildPlan
@@ -79,6 +82,7 @@ library
7982
Bootstrap.Nix.Expr.Python
8083
Bootstrap.Nix.Expr.ReproducibleBuild.Go
8184
Bootstrap.Nix.Expr.ReproducibleBuild.Java
85+
Bootstrap.Nix.Expr.ReproducibleBuild.Rust
8286
Bootstrap.Nix.Flake
8387
Bootstrap.State
8488
Bootstrap.Terminal
@@ -188,6 +192,9 @@ test-suite nix-bootstrap-test
188192
Bootstrap.Data.Bootstrappable.NixShellCompatSpec
189193
Bootstrap.Data.Bootstrappable.NixShellSpec
190194
Bootstrap.Data.Bootstrappable.ReadmeSpec
195+
Bootstrap.Data.Bootstrappable.Rust.CargoLockSpec
196+
Bootstrap.Data.Bootstrappable.Rust.CargoTomlSpec
197+
Bootstrap.Data.Bootstrappable.Rust.MainRsSpec
191198
Bootstrap.Data.Bootstrappable.VSCodeExtensionsSpec
192199
Bootstrap.Data.Bootstrappable.VSCodeSettingsSpec
193200
Bootstrap.Data.BuildPlanSpec
@@ -198,6 +205,7 @@ test-suite nix-bootstrap-test
198205
Bootstrap.Data.ProjectTypeSpec
199206
Bootstrap.Data.VersionSpec
200207
Bootstrap.Nix.CommandSpec
208+
Bootstrap.Nix.Expr.MkShellSpec
201209
Bootstrap.Nix.Expr.NixpkgsSpec
202210
Bootstrap.Nix.ExprSpec
203211
Bootstrap.Nix.FlakeSpec

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
name: nix-bootstrap
15-
version: 1.4.1.0
15+
version: 1.5.0.0
1616
author: gchquser
1717
maintainer: [email protected]
1818
copyright: Crown Copyright

src/Bootstrap.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Bootstrap.Data.Bootstrappable
1616
( Bootstrappable (bootstrapName),
1717
)
1818
import Bootstrap.Data.Bootstrappable.BuildNix (buildNixFor)
19-
import Bootstrap.Data.Bootstrappable.DefaultNix (defaultNixFor)
19+
import Bootstrap.Data.Bootstrappable.DefaultNix (SrcDir (SrcDirCurrent), defaultNixFor)
2020
import Bootstrap.Data.Bootstrappable.DevContainer
2121
( devContainerDockerComposeFor,
2222
devContainerDockerfileFor,
@@ -57,6 +57,9 @@ import Bootstrap.Data.Bootstrappable.Readme
5757
readmeUseFlakes
5858
),
5959
)
60+
import Bootstrap.Data.Bootstrappable.Rust.CargoLock (cargoLockFor)
61+
import Bootstrap.Data.Bootstrappable.Rust.CargoToml (cargoTomlFor)
62+
import Bootstrap.Data.Bootstrappable.Rust.MainRs (mainRsFor)
6063
import Bootstrap.Data.Bootstrappable.VSCodeExtensions (vsCodeExtensionsFileFor)
6164
import Bootstrap.Data.Bootstrappable.VSCodeSettings (vsCodeSettingsFor)
6265
import Bootstrap.Data.BuildPlan
@@ -106,9 +109,10 @@ import Bootstrap.Data.ProjectType
106109
PSTJava,
107110
PSTMinimal,
108111
PSTNode,
109-
PSTPython
112+
PSTPython,
113+
PSTRust
110114
),
111-
ProjectType (Elm, Go, Haskell, Java, Minimal, Node, Python),
115+
ProjectType (Elm, Go, Haskell, Java, Minimal, Node, Python, Rust),
112116
PythonVersion (Python39),
113117
SetUpGoBuild (SetUpGoBuild),
114118
SetUpJavaBuild (NoJavaBuild, SetUpJavaBuild),
@@ -428,6 +432,7 @@ promptProjectType nixBinaryPaths runConfig devContainerConfig = do
428432
<$> promptNonemptyText "Enter your Maven ArtefactId (e.g. the 'demo' in 'com.example.demo'): "
429433
pure . Java $ JavaOptions installMinishift installLombok setUpJavaBuild
430434
PSTPython -> pure $ Python Python39
435+
PSTRust -> pure Rust
431436
where
432437
askIfReproducibleBuildRequired :: m Bool
433438
askIfReproducibleBuildRequired = promptYesNoWithCustomPrompt do
@@ -497,7 +502,7 @@ makeBuildPlan MakeBuildPlanArgs {..} = do
497502
)
498503
~: ( if rcUseFlakes mbpRunConfig
499504
then Nothing
500-
else defaultNixFor mbpProjectName mbpProjectType
505+
else defaultNixFor SrcDirCurrent mbpProjectName mbpProjectType
501506
)
502507
~: nixShellCompatFor mbpRunConfig
503508
~: nixPreCommitHookConfig
@@ -520,6 +525,9 @@ makeBuildPlan MakeBuildPlanArgs {..} = do
520525
~: preludeHsFor mbpProjectType
521526
~: libHsFor mbpProjectType
522527
~: mainHsFor mbpProjectType
528+
~: cargoLockFor mbpProjectType mbpProjectName
529+
~: cargoTomlFor mbpProjectType mbpProjectName
530+
~: mainRsFor mbpProjectType
523531
~: GitPodYml
524532
~: HNil
525533
)

src/Bootstrap/Data/Bootstrappable/BuildNix.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Bootstrap.Data.Bootstrappable
1212
)
1313
import Bootstrap.Data.Bootstrappable.DefaultNix
1414
( DefaultNix (defaultNixInBlockExpr),
15+
SrcDir (SrcDirParent),
1516
defaultNixFor,
1617
)
1718
import Bootstrap.Data.ProjectName (ProjectName)
@@ -37,7 +38,7 @@ buildNixFor :: RunConfig -> ProjectName -> ProjectType -> Maybe BuildNix
3738
buildNixFor RunConfig {rcUseFlakes} flakeNixProjectName flakeNixProjectType =
3839
let buildExpr =
3940
defaultNixInBlockExpr
40-
<$> defaultNixFor flakeNixProjectName flakeNixProjectType
41+
<$> defaultNixFor SrcDirParent flakeNixProjectName flakeNixProjectType
4142
in if rcUseFlakes
4243
then BuildNix <$> buildExpr
4344
else Nothing

src/Bootstrap/Data/Bootstrappable/DefaultNix.hs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-- | Copyright : (c) Crown Copyright GCHQ
55
module Bootstrap.Data.Bootstrappable.DefaultNix
66
( DefaultNix (defaultNixInBlockExpr),
7+
SrcDir (..),
78
defaultNixFor,
89
)
910
where
@@ -13,16 +14,32 @@ import Bootstrap.Data.Bootstrappable
1314
bootstrapContentNix,
1415
)
1516
import Bootstrap.Data.ProjectName (ProjectName)
16-
import Bootstrap.Data.ProjectType (JavaOptions (JavaOptions), ProjectType (Go, Java), SetUpGoBuild (SetUpGoBuild), SetUpJavaBuild (SetUpJavaBuild))
17+
import Bootstrap.Data.ProjectType
18+
( JavaOptions (JavaOptions),
19+
ProjectType
20+
( Elm,
21+
Go,
22+
Haskell,
23+
Java,
24+
Minimal,
25+
Node,
26+
Python,
27+
Rust
28+
),
29+
SetUpGoBuild (SetUpGoBuild),
30+
SetUpJavaBuild (SetUpJavaBuild),
31+
)
1732
import Bootstrap.Nix.Expr
1833
( Expr (ELetIn),
1934
IsNixExpr (toNixExpr),
35+
nix,
2036
nixproperty,
2137
(|=),
2238
)
2339
import Bootstrap.Nix.Expr.Nixpkgs (nixpkgsFromNiv)
2440
import Bootstrap.Nix.Expr.ReproducibleBuild.Go (reproducibleGoBuild)
2541
import Bootstrap.Nix.Expr.ReproducibleBuild.Java (reproducibleJavaBuild)
42+
import Bootstrap.Nix.Expr.ReproducibleBuild.Rust (reproducibleRustBuild)
2643

2744
newtype DefaultNix = DefaultNix {defaultNixInBlockExpr :: Expr}
2845

@@ -35,8 +52,27 @@ instance IsNixExpr DefaultNix where
3552
toNixExpr DefaultNix {..} =
3653
ELetIn (one $ [nixproperty|nixpkgs|] |= nixpkgsFromNiv) defaultNixInBlockExpr
3754

38-
defaultNixFor :: ProjectName -> ProjectType -> Maybe DefaultNix
39-
defaultNixFor projectName = \case
55+
-- | The source directory for the build
56+
data SrcDir
57+
= -- | src = ./.;
58+
SrcDirCurrent
59+
| -- | src = ../.;
60+
SrcDirParent
61+
62+
srcDirExpr :: SrcDir -> Expr
63+
srcDirExpr = \case
64+
SrcDirCurrent -> [nix|./.|]
65+
SrcDirParent -> [nix|../.|]
66+
67+
defaultNixFor :: SrcDir -> ProjectName -> ProjectType -> Maybe DefaultNix
68+
defaultNixFor srcDir projectName = \case
69+
Minimal -> Nothing
70+
Elm _ -> Nothing
71+
Haskell _ -> Nothing
72+
Node _ -> Nothing
4073
Go (SetUpGoBuild True) -> Just . DefaultNix $ reproducibleGoBuild projectName
74+
Go _ -> Nothing
4175
Java (JavaOptions _ _ (SetUpJavaBuild artefactId)) -> Just . DefaultNix $ reproducibleJavaBuild projectName artefactId
42-
_ -> Nothing
76+
Java _ -> Nothing
77+
Python _ -> Nothing
78+
Rust -> Just . DefaultNix . reproducibleRustBuild $ srcDirExpr srcDir

src/Bootstrap/Data/Bootstrappable/FlakeNix.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Bootstrap.Data.Bootstrappable.NixShell
2121
nixShellExtraBindings,
2222
nixShellHooksRequireNixpkgs,
2323
nixShellNixpkgsBuildInputs,
24+
nixShellNixpkgsNativeBuildInputs,
2425
nixShellOtherBuildInputs
2526
),
2627
nixShellFor,
@@ -45,7 +46,7 @@ import Bootstrap.Nix.Expr
4546
(|:),
4647
(|=),
4748
)
48-
import Bootstrap.Nix.Expr.BuildInputs (BuildInputSpec (bisOtherPackages))
49+
import Bootstrap.Nix.Expr.BuildInputs (BuildInputSpec (bisNativeNixpkgsPackages, bisOtherPackages))
4950
import Bootstrap.Nix.Expr.MkShell
5051
( BuildInputSpec
5152
( BuildInputSpec,
@@ -71,6 +72,7 @@ data FlakeNix = FlakeNix
7172
flakeNixExtraBindings :: [Binding],
7273
flakeNixNixpkgsBuildInputs :: [Expr],
7374
flakeNixOtherBuildInputs :: [Expr],
75+
flakeNixNixpkgsNativeBuildInputs :: [Expr],
7476
flakeNixBuildNix :: Maybe BuildNix,
7577
-- | Used to determine whether to pass the nixpkgs argument to the pre-commit-hooks config
7678
flakeNixHooksRequireNixpkgs :: Bool
@@ -104,6 +106,7 @@ flakeNixFor
104106
{ nixShellExtraBindings,
105107
nixShellNixpkgsBuildInputs,
106108
nixShellOtherBuildInputs,
109+
nixShellNixpkgsNativeBuildInputs,
107110
nixShellHooksRequireNixpkgs
108111
} =
109112
nixShellFor rc flakeNixProjectType flakeNixPreCommitHooksConfig nixPreCommitHookConfig
@@ -114,6 +117,7 @@ flakeNixFor
114117
{ flakeNixExtraBindings = (nixShellExtraBindings ^.. folded . filtered fst . _2) <> extraBindings,
115118
flakeNixNixpkgsBuildInputs = nixShellNixpkgsBuildInputs,
116119
flakeNixOtherBuildInputs = nixShellOtherBuildInputs,
120+
flakeNixNixpkgsNativeBuildInputs = nixShellNixpkgsNativeBuildInputs,
117121
flakeNixHooksRequireNixpkgs = nixShellHooksRequireNixpkgs,
118122
..
119123
}
@@ -187,7 +191,8 @@ instance IsNixExpr FlakeNix where
187191
{ bisNixpkgsPackages = flakeNixNixpkgsBuildInputs,
188192
bisOtherPackages = flakeNixOtherBuildInputs,
189193
bisPreCommitHooksConfig = flakeNixPreCommitHooksConfig,
190-
bisProjectType = flakeNixProjectType
194+
bisProjectType = flakeNixProjectType,
195+
bisNativeNixpkgsPackages = flakeNixNixpkgsNativeBuildInputs
191196
}
192197
]
193198
<> case flakeNixBuildNix of

0 commit comments

Comments
 (0)