unison/development.markdown

190 lines
7.2 KiB
Markdown
Raw Normal View History

These are commands that will likely be useful during development.
2019-03-29 00:21:20 +03:00
__General:__ `./scripts/test.sh` compiles and builds the Haskell code and runs all tests. Recommended that you run this before pushing any code to a branch that others might be working on.
2024-02-29 22:01:39 +03:00
_Disclaimer_ If you have trouble getting started, please get in touch via [Discord](https://unison-lang.org/discord) so we can help. If you have any fixes to the process, please send us a PR!
## Running Unison
To get cracking with Unison:
1. [Install `stack`](https://docs.haskellstack.org/en/stable/README/#how-to-install).
2. Build the project with `stack build`. This builds all executables.
3. (Optional) Run `./dev-ui-install.hs` to fetch the latest release of the codebase UI. If you don't care about running the codebase UI locally you can ignore this step.
2022-06-06 17:56:09 +03:00
4. After building do `stack exec unison` to will initialize a codebase in your home directory (in `~/.unison`). This only needs to be done once. (Alternatively, you can use `stack exec -- unison -C <other dir> to create a codebase in <other dir>`
5. `stack exec unison` starts Unison and watches for `.u` file changes in the current directory. If you want to run it in a different directory, just add `unison` to your `PATH`, after finding it with `stack exec which unison`.
On startup, Unison prints a url for the codebase UI. If you did step 3 above, then visiting that URL in a browser will give you a nice interface to your codebase.
2021-03-21 18:32:27 +03:00
## Autoformatting your code with Ormolu
We use 0.5.0.1 of Ormolu and CI will add an extra commit, if needed, to autoformat your code.
Also note that you can always wrap a comment around some code you don't want Ormolu to touch, using:
```
{- ORMOLU_DISABLE -}
dontFormatMe = do blah
blah
blah
{- ORMOLU_ENABLE -}
```
2021-03-21 18:32:27 +03:00
## Running Tests
* `stack test --fast` builds and runs most test suites, see below for exceptions to this (e.g. transcript tests).
Most test suites support selecting a specific test to run by passing a prefix as a test argument:
2022-06-29 07:48:12 +03:00
* `stack test unison-parser-typechecker --fast --test-arguments my-test-prefix` builds and runs most test suites, see below for exceptions to this (e.g. transcript tests).
Some tests are executables instead:
2021-10-24 11:20:51 +03:00
* `stack exec transcripts` runs the transcripts-related integration tests, found in `unison-src/transcripts`. You can add more tests to this directory.
* `stack exec transcripts -- prefix-of-filename` runs only transcript tests with a matching filename prefix.
2024-05-11 01:09:16 +03:00
* `stack exec integration-tests` runs the additional integration tests for cli. These tests are not triggered by `tests` or `transcripts`.
* `stack exec unison -- transcript unison-src/transcripts-round-trip/main.md` runs the pretty-printing round trip tests
2022-12-05 21:41:11 +03:00
* `stack exec unison -- transcript unison-src/transcripts-manual/benchmarks.md` runs the benchmark suite. Output goes in unison-src/transcripts-manual/benchmarks/output.txt.
2022-06-06 17:56:09 +03:00
### Building everything at once, including tests and benchmarks, but without running them:
Do:
stack build --fast --test --bench --no-run-tests --no-run-benchmarks
2019-03-29 00:46:39 +03:00
### What if you want a profiled build?
2019-03-29 00:46:39 +03:00
Do:
2019-03-30 01:02:36 +03:00
2022-06-06 17:56:09 +03:00
stack build --profile unison-parser-typechecker
Again you can leave off the flag. To run an executable with profiling enabled, do:
stack exec -- <executable-name> +RTS -p
That will generate a `<executable-name>.prof` plain text file with profiling data. [More info on profiling](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html).
## Building with cabal
2021-06-19 00:19:00 +03:00
Unison can also be built/installed with cabal. You'll need the same ghc
used by `stack.yaml` to successfully build its dependencies.
The provided project file is also in contrib/ so you'll need to specify
its location on the command line.
* To build all projects use
`cabal v2-build --project-file=contrib/cabal.project all`
* Tests can be run with e.g.
`cabal v2-test --project-file=contrib/cabal.project all`
* The executable can be installed with
`cabal v2-install --project-file=contrib/cabal.project unison`
* The install directory can be modified with the option `--installdir: ...`
2023-01-08 19:09:28 +03:00
* Take in account that if you want to load the project in haskell-language-server using cabal instead stack you will need:
* Copy or link `./contrib/cabal.project` to `./cabal.project`
* Delete or rename the existing `./hie.yaml`. The default behaviour without `hie.yaml` works with cabal.
## Building on Windows
### I get an error about unison/sql/something
2022-07-29 21:04:19 +03:00
This codebase uses symlinks as a workaround for some inconveniences in the `here` package. Support for symlinks in Windows is relatively new, and isn't enabled by default. As a result, your cloned copy of the code probably won't build.
First you'll need to enable "Developer Mode" in your Windows settings.
2022-07-29 21:42:08 +03:00
See https://consumer.huawei.com/en/support/content/en-us15594140/
Then you'll need to enable symlink support in your `git` configuration, e.g.
`git config core.symlinks true`
And then ask `git` to fix up your symlinks with `git checkout .`
More context at: https://stackoverflow.com/a/59761201/310162
### I get an error about `removeDirectoryRecursive`/`removeContentsRecursive`/`removePathRecursive`/`permission denied (Access is denied.)`
Stack doesn't work deterministically in Windows due to mismatched expectations about how file deletion works. If you get this error, you can just retry the build and it will probably make more progress than the last time.
2023-06-13 23:18:52 +03:00
## Building with Nix
## Building package components with nix
### Build the unison executable
```
nix build
```
### Build a specific component
This is specified with the normal
`<package>:<component-type>:<component-name>` triple.
Some examples:
```
nix build '.#component-unison-cli:lib:unison-cli'
nix build '.#component-unison-syntax:test:syntax-tests'
nix build '.#component-unison-cli:exe:transcripts'
2023-06-13 23:18:52 +03:00
```
### Development environments
#### Get into a development environment for building with stack
This gets you into a development environment with the preferred
versions of the compiler and other development tools. These
include:
- ghc
- stack
- ormolu
- haskell-language-server
```
nix develop
```
#### Get into a development environment for building with cabal
This gets you into a development environment with the preferred
versions of the compiler and other development tools. Additionally,
all non-local haskell dependencies (including profiling dependencies)
are provided in the nix shell.
```
nix develop '.#cabal-local'
2023-06-13 23:18:52 +03:00
```
#### Get into a development environment for building a specific package
This gets you into a development environment with the preferred
versions of the compiler and other development tools. Additionally,
all haskell dependencies of this package are provided by the nix shell
(including profiling dependencies).
```
nix develop '.#cabal-<package-name>'
2023-06-13 23:18:52 +03:00
```
for example:
```
nix develop '.#cabal-unison-cli'
2023-06-13 23:18:52 +03:00
```
or
```
nix develop '.#cabal-unison-parser-typechecker'
2023-06-13 23:18:52 +03:00
```
This is useful if you wanted to profile a package. For example, if you
want to profile `unison-cli-main:exe:unison` then you could get into one of these
2023-06-13 23:18:52 +03:00
shells, cd into its directory, then run the program with
profiling.
```
nix develop '.#cabal-unison-parser-typechecker'
2023-06-13 23:18:52 +03:00
cd unison-cli
cabal run --enable-profiling unison-cli-main:exe:unison -- +RTS -p
2023-06-13 23:18:52 +03:00
```