|
6 | 6 |
|
7 | 7 | ??? question "What is the relationship between Stack and Cabal?" |
8 | 8 |
|
9 | | -<<<<<<< HEAD |
10 | | -The version of GHC, as well as which packages can be installed, are specified by |
11 | | -the _snapshot_. This may be something like `lts-22.28`, which is from |
12 | | -[Stackage](https://www.stackage.org/). The |
13 | | -[user's guide](tutorial/building_your_project.md) discusses the snapshot in more |
14 | | -detail. |
15 | | -======= |
16 | 9 | 'Cabal' can refer to Cabal (the library) or to Cabal (the tool). |
17 | | ->>>>>>> stable |
18 | 10 |
|
19 | 11 | === "Cabal (the library)" |
20 | 12 |
|
@@ -63,302 +55,13 @@ detail. |
63 | 55 | The concept of sandboxes is built-in with Stack. All builds are |
64 | 56 | automatically isolated into separate package databases. |
65 | 57 |
|
66 | | -<<<<<<< HEAD |
67 | | -~~~yaml |
68 | | -snapshot: lts-22.28 |
69 | | -packages: |
70 | | -- . |
71 | | -extra-deps: |
72 | | -- text-2.1.1@rev:0 |
73 | | -~~~ |
74 | | -======= |
75 | 58 | ??? question "Can I run `cabal` commands inside `stack exec`?" |
76 | | ->>>>>>> stable |
77 | 59 |
|
78 | 60 | Yes. Some `cabal` commands are inconsistent with the `GHC_PACKAGE_PATH` |
79 | 61 | environment variable in the Stack environment. Command, for example: |
80 | 62 |
|
81 | | -<<<<<<< HEAD |
82 | | -Add it to the |
83 | | -[`extra-deps`](configure/yaml/project-specific_configuration.md#extra-deps) list |
84 | | -in your project's `stack.yaml` file, specifying the package's source code |
85 | | -location relative to the directory where your `stack.yaml` file lives, e.g. |
86 | | - |
87 | | -~~~yaml |
88 | | -snapshot: lts-22.28 |
89 | | -packages: |
90 | | -- . |
91 | | -extra-deps: |
92 | | -- third-party/proprietary-dep |
93 | | -- github-version-of/conduit |
94 | | -- patched/diagrams |
95 | | -~~~ |
96 | | - |
97 | | -The above example specifies that the `proprietary-dep` package is found in the |
98 | | -project's `third-party` directory, that the `conduit` package is found in the |
99 | | -project's `github-version-of` directory, and that the `diagrams` package is |
100 | | -found in the project's `patched` directory. This autodetects changes and |
101 | | -reinstalls the package. |
102 | | - |
103 | | -To install packages directly from a Git repository, use e.g.: |
104 | | - |
105 | | -~~~yaml |
106 | | -extra-deps: |
107 | | - - git: https://github.com/githubuser/reponame.git |
108 | | - commit: somecommitID |
109 | | -~~~ |
110 | | - |
111 | | -## What is the meaning of the arguments given to `stack build`, `test`, etc? |
112 | | - |
113 | | -Those are the targets of the build, and can have one of three formats: |
114 | | - |
115 | | -* A package name (e.g., `my-package`) will mean that the `my-package` package |
116 | | - must be built |
117 | | -* A package identifier (e.g., `my-package-1.2.3`), which includes a specific |
118 | | - version. This is useful for passing to `stack install` for getting a specific |
119 | | - version from upstream |
120 | | -* A directory (e.g., `./my-package`) for including a local directory's package, |
121 | | - including any packages in subdirectories |
122 | | - |
123 | | -## I need to modify an upstream package, how should I do it? |
124 | | - |
125 | | -Typically, you will want to get the source for the package and then add it to |
126 | | -your `packages` list in the `stack.yaml` file. (See the previous question.) |
127 | | -`stack unpack` is one approach for getting the source. Another would be to add |
128 | | -the upstream package as a submodule to your project. |
129 | | - |
130 | | -## How do I use this with sandboxes? |
131 | | - |
132 | | -Explicit sandboxing on the part of the user is not required by Stack. All |
133 | | -builds are automatically isolated into separate package databases without any |
134 | | -user interaction. This ensures that you won't accidentally corrupt your |
135 | | -installed packages with actions taken in other projects. |
136 | | - |
137 | | -## Can I run `cabal` commands inside `stack exec`? |
138 | | - |
139 | | -With a recent enough version of Cabal (the tool) (1.22 or later), you can. For |
140 | | -earlier versions this does not work, due to Cabal issue |
141 | | -[#1800](https://github.com/haskell/cabal/issues/1800). Note that |
142 | | -even with recent versions, for some commands you may need the following extra |
143 | | -level of indirection. Command: |
144 | | - |
145 | | -~~~text |
146 | | -stack exec -- cabal exec -- cabal <command> |
147 | | -~~~ |
148 | | - |
149 | | -However, virtually all `cabal` commands have an equivalent in Stack, so this |
150 | | -should not be necessary. In particular, users of Cabal (the tool) may be |
151 | | -accustomed to the `cabal run` command. With Stack, command: |
152 | | - |
153 | | -~~~text |
154 | | -stack build |
155 | | -stack exec <program-name> |
156 | | -~~~ |
157 | | - |
158 | | -Or, if you want to install the binaries in a shared location, command: |
159 | | - |
160 | | -~~~text |
161 | | -stack install <program-name> |
162 | | -~~~ |
163 | | - |
164 | | -assuming your PATH has been set appropriately. |
165 | | - |
166 | | -## Using custom preprocessors |
167 | | - |
168 | | -If you have a custom preprocessor, for example, Ruby, you may have a file like: |
169 | | - |
170 | | -***B.erb*** |
171 | | - |
172 | | -~~~haskell |
173 | | -module B where |
174 | | - |
175 | | -<% (1..5).each do |i| %> |
176 | | -test<%= i %> :: Int |
177 | | -test<%= i %> = <%= i %> |
178 | | -<% end %> |
179 | | -~~~ |
180 | | - |
181 | | -To ensure that Stack picks up changes to this file for rebuilds, add the |
182 | | -following lines to your `stack.yaml` file: |
183 | | - |
184 | | -~~~yaml |
185 | | -custom-preprocessor-extensions: |
186 | | -- erb |
187 | | - |
188 | | -require-stack-version: ">= 2.6.0" |
189 | | -~~~ |
190 | | - |
191 | | -And for backwards compatability with older versions of Stack, also add the |
192 | | -following line to your Cabal file: |
193 | | - |
194 | | - extra-source-files: B.erb |
195 | | - |
196 | | -You could also use the |
197 | | -[`--custom-preprocessor-extensions`](configure/yaml/project.md#custom-preprocessor-extensions) |
198 | | -flag. |
199 | | - |
200 | | -## I already have GHC installed, can I still use Stack? |
201 | | - |
202 | | -Yes. In its default configuration, Stack will simply ignore any system GHC |
203 | | -installation and use a sandboxed GHC that it has installed itself. You can find |
204 | | -these sandboxed GHC installations in the `ghc-*` directories in the |
205 | | -`stack path --programs` directory. |
206 | | - |
207 | | -If you would like Stack to use your system GHC installation, use the |
208 | | -[`--system-ghc`](configure/yaml/non-project.md#system-ghc) flag or run |
209 | | -`stack config set system-ghc --global true` to make Stack check your PATH for a |
210 | | -suitable GHC by default. |
211 | | - |
212 | | -Stack can only use a system GHC installation if its version is compatible with |
213 | | -the configuration of the current project, particularly the snapshot specified by |
214 | | -the [`snapshot`](configure/yaml/project.md#snapshot) or |
215 | | -[`resolver`](configure/yaml/project.md#resolver) key. |
216 | | - |
217 | | -GHC installation doesn't work for all operating systems, so in some cases you |
218 | | -will need to use `system-ghc` and install GHC yourself. |
219 | | - |
220 | | -## How does Stack determine what GHC to use? |
221 | | - |
222 | | -In its default configuration, Stack determines from the current project which |
223 | | -GHC version, architecture etc it needs. It then looks in the `ghc-<version>` |
224 | | -subdirectory of the `stack path --programs` directory for a compatible GHC, |
225 | | -requesting to install one via `stack setup` if none is found. |
226 | | - |
227 | | -If you are using the [`--system-ghc`](configure/yaml/non-project.md#system-ghc) |
228 | | -flag or have configured `system-ghc: true` either in the project `stack.yaml` or |
229 | | -the global `config.yaml`, Stack will use the first GHC that it finds on your |
230 | | -PATH, falling back on its sandboxed installations only if the found GHC doesn't |
231 | | -comply with the various requirements (version, architecture) that your project |
232 | | -needs. |
233 | | - |
234 | | -See issue [#420](https://github.com/commercialhaskell/stack/issues/420) for a |
235 | | -detailed discussion of Stack's behavior when `system-ghc` is enabled. |
236 | | - |
237 | | -## How do I get extra tools used during building? |
238 | | - |
239 | | -Stack will automatically install tools used during building required by your |
240 | | -packages or their dependencies, in particular |
241 | | -[Alex](https://hackage.haskell.org/package/alex) and |
242 | | -[Happy](https://hackage.haskell.org/package/happy). |
243 | | - |
244 | | -!!! note |
245 | | - |
246 | | - This works when using LTS or nightly snapshots, not with GHC or custom |
247 | | - snapshots. You can manually install tools used during building by running, |
248 | | - e.g., `stack build alex happy`. |
249 | | - |
250 | | -## How does Stack choose which snapshot to use when creating a new configuration file? |
251 | | - |
252 | | -It checks the two most recent LTS Haskell major versions and the most recent |
253 | | -Stackage Nightly for a snapshot that is compatible with all of the version |
254 | | -bounds in your Cabal file, favoring the most recent LTS. For more information, |
255 | | -see the snapshot auto-detection section in the architecture document. |
256 | | - |
257 | | -## I'd like to use my installed packages in a different directory. How do I tell Stack where to find my packages? |
258 | | - |
259 | | -Set the `STACK_YAML` environment variable to point to the `stack.yaml` |
260 | | -configuration file for your project. Then you can run `stack exec`, `stack ghc`, |
261 | | -etc., from any directory and still use your packages. |
262 | | - |
263 | | -## My tests are failing. What should I do? |
264 | | - |
265 | | -Like all other targets, `stack test` runs test suites in parallel by default. |
266 | | -This can cause problems with test suites that depend on global resources such |
267 | | -as a database or binding to a fixed port number. A quick hack is to force stack |
268 | | -to run all test suites in sequence, using `stack test --jobs=1`. For test |
269 | | -suites to run in parallel developers should ensure that their test suites do |
270 | | -not depend on global resources (e.g. by asking the operating system for a random |
271 | | -port to bind to) and where unavoidable, add a lock in order to serialize access |
272 | | -to shared resources. |
273 | | - |
274 | | -## Can I get bash autocompletion? |
275 | | - |
276 | | -Yes, see the [shell-autocompletion](shell_autocompletion.md) documentation. |
277 | | - |
278 | | -## How do I update my package index? |
279 | | - |
280 | | -Users of Cabal (the tool) are used to running `cabal update` regularly. You can |
281 | | -do the same with Stack by running `stack update`. But generally, it's not |
282 | | -necessary: if the package index is missing, or if a snapshot refers to |
283 | | -package/version that isn't available, Stack will automatically update and then |
284 | | -try again. If you run into a situation where Stack doesn't automatically do the |
285 | | -update for you, please report it as a bug. |
286 | | - |
287 | | -## Isn't it dangerous to automatically update the index? Can't that corrupt build plans? |
288 | | - |
289 | | -No, Stack is very explicit about which packages it's going to build for you. |
290 | | -There are three sources of information to tell it which packages to install: |
291 | | -the selected snapshot, the `extra-deps` configuration value, and your local |
292 | | -packages. The only way to get Stack to change its build plan is to modify one |
293 | | -of those three. Updating the index will have no impact on Stack's behavior. |
294 | | - |
295 | | -## I have a custom package index I'd like to use, how do I do so? |
296 | | - |
297 | | -You can configure this in your project-level configuration file (`stack.yaml`, |
298 | | -by default). See [YAML configuration](configure/yaml/yaml_configuration.md). |
299 | | - |
300 | | -## How can I make sure my project builds against multiple GHC versions? |
301 | | - |
302 | | -You can create multiple YAML configuration files for your project, one for each |
303 | | -build plan. For example, you might set up your project directory like so: |
304 | | - |
305 | | -~~~text |
306 | | -myproject/ |
307 | | - stack-ghc-9.0.2.yaml |
308 | | - stack-ghc-9.2.4.yaml |
309 | | - stack.yaml --> symlink to stack-ghc-9.2.4.yaml |
310 | | - myproject.cabal |
311 | | - src/ |
312 | | - ... |
313 | | -~~~ |
314 | | - |
315 | | -When you run `stack build`, you can set the `STACK_YAML` environment variable to |
316 | | -indicate which build plan to use. On Unix-like operating systems command: |
317 | | - |
318 | | -~~~bash |
319 | | -stack build # builds using the default stack.yaml |
320 | | -STACK_YAML=stack-ghc-7.10.yaml |
321 | | -stack build # builds using the given yaml file |
322 | | -~~~ |
323 | | - |
324 | | -On Windows (with PowerShell) command: |
325 | | - |
326 | | -~~~ps |
327 | | -$Env:STACK_YAML='stack-ghc-9.0.2.yaml' |
328 | | -stack build |
329 | | -~~~ |
330 | | - |
331 | | -## I heard you can use this with Docker? |
332 | | - |
333 | | -Yes, Stack supports using Docker with images that contain preinstalled Stackage |
334 | | -packages and the tools. See [Docker integration](topics/docker_integration.md) |
335 | | -for details. |
336 | | - |
337 | | -## How do I build a statically-linked executable on Linux? |
338 | | - |
339 | | -The way that Stack itself builds statically-linked Stack executables for Linux |
340 | | -is as follows: |
341 | | - |
342 | | -* In the Cabal file, the following |
343 | | - [`ld-options`](https://cabal.readthedocs.io/en/stable/cabal-package.html#pkg-field-ld-options) |
344 | | - are set: `-static` and `-pthread`. |
345 | | - |
346 | | -* The Stack command is run in a Docker container based on Alpine Linux. The |
347 | | - relevant Docker image repository is set out in Stack's `stack.yaml` file. See |
348 | | - also Olivier Benz's [GHC musl project](https://gitlab.com/benz0li/ghc-musl). |
349 | | - |
350 | | -* Stack's configuration includes: |
351 | | - |
352 | | - ~~~yaml |
353 | | - extra-include-dirs: |
354 | | - - /usr/include |
355 | | - extra-lib-dirs: |
356 | | - - /lib |
357 | | - - /usr/lib |
358 | | -======= |
359 | 63 | ~~~text |
360 | 64 | stack exec --no-ghc-package-path -- cabal build |
361 | | ->>>>>>> stable |
362 | 65 | ~~~ |
363 | 66 |
|
364 | 67 | ## GHC or GHCi-related |
|
0 commit comments