Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add devbox integration #38

Open
wants to merge 5 commits into
base: lamdera-next
Choose a base branch
from

Conversation

seanstrom
Copy link

Summary

  • This PR attempts to integrate Devbox for managing and provisioning the development environment.
    • Additionally, this PR integrates a .envrc file for integrating Direnv with Devbox. This is an optional feature, but it can be convenient for entering a Devbox workspace and automatically have the shell env prepared.
  • This PR was tested locally on macOS using commands like stack install, stack build, and stack ghci.
    • There may be some unresolved issues for other platforms like Linux or Windows.

devbox.json Outdated
Comment on lines 9 to 17
"zlib": {
"version": "latest",
"outputs": ["out", "dev"]
},
"hpack": "latest"
},
"env": {
"LD_LIBRARY_PATH": "$DEVBOX_PACKAGES_DIR/lib:$LD_LIBRARY_PATH"
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems important that the zlib dependency has the outputs field, and that we export the LD_LIBRARY_PATH env variable. Otherwise, we would have issues with pkg-config finding the zlib library during compilation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, nice. I've had issues with zlib paths before – I guess this fixes that!

devbox.json Outdated
Comment on lines 18 to 27
"shell": {
"init_hook": [
"echo 'Welcome to devbox!' > /dev/null"
],
"scripts": {
"test": [
"echo \"Error: no test specified\" && exit 1"
]
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to remove the init_hook and scripts fields, but let me know if we would like any additions like some useful scripts or something 🙏

Copy link
Member

@supermario supermario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks @seanstrom !

Some minor feedback.

Also; when I run devbox shell and then stack ghci I see this error printed out about 120 times:

gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'

Any idea why? I see gcc is version pinned, I guess latest had some issues?

.envrc Outdated
# Automatically sets up your devbox environment whenever you cd into this
# directory via our direnv integration:

eval "$(devbox generate direnv --print-envrc)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice, but I don't think this should be the default for direnv, as I think more folks use direnv than they do devbox so the first thing they'd get greeted with is an odd error upon entering the project dir.

Happy to keep it as .envrc-devbox and add a note in the readme that a devbox setup is available and that optionally you can also use it automatically with direnv if you like.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah good point!
I'll rename the file to .envrc-devbox and update the docs too 👍

@seanstrom
Copy link
Author

Also; when I run devbox shell and then stack ghci I see this error printed out about 120 times:

gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'

Any idea why? I see gcc is version pinned, I guess latest had some issues?

I think this error happens when dependencies use the GCC compiler and attempt to cross-compile. I recall reading that GCC doesn't support the flag --target=arm64-apple-darwin, so I needed to use Clang for the compilation of those dependencies.

At the moment, I'm not able to reproduce that issue again, so I'll need a moment to figure out how to reset my env to test this again.

In the mean time, maybe try overriding / exporting an environment variable like: export CC=clang
I recall this being the workaround that I used during some of my tinkering.

On a side note, what is the reason for needing GCC in this project? Would Clang be okay for compiling the dependencies?

@supermario
Copy link
Member

It's a long time since I set things up so I don't recall if gcc specifically was required.

Just tried running a recompile in ghci and that seems to have a hard failure if that helps repro;

ghci> :rr
gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'
gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'
`gcc' failed in phase `Linker'. (Exit code: 1)
[188 of 218] Compiling Lamdera.Injection ( /Users/mario/dev/projects/lamdera-compiler/extra/Lamdera/Injection.hs, /Users/mario/dev/projects/lamdera-compiler/.stack-work/odir/Lamdera/Injection.o )
gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'
gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'
`gcc' failed in phase `Linker'. (Exit code: 1)

<interactive>:1:1: error:
    Not in scope: ‘Test.target’
    No module named ‘Test’ is imported.

@seanstrom
Copy link
Author

@supermario I've pushed up some changes that should set the desired C compiler to be Clang during compilation. Can you pull down these changes and try re-entering the devbox shell?

Also it would be good to confirm what running: echo $CC prints before and after entering the devbox shell.

@supermario
Copy link
Member

@seanstrom hrm different issue now 🤔

$ stack install
[1 of 2] Compiling Main             ( /Users/mario/.stack/setup-exe-src/setup-CKvAmRb3.hs, /Users/mario/.stack/setup-exe-src/setup-CKvAmRb3.o )
gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'
`gcc' failed in phase `Assembler'. (Exit code: 1)

Error: [S-6374]
       While building simple Setup.hs (scroll up to its section to see the error) using:
       /Users/mario/.ghcup/ghc/9.2.8/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.6.3.0 /Users/mario/.stack/setup-exe-src/setup-CKvAmRb3.hs /Users/mario/.stack/setup-exe-src/setup-shim-CKvAmRb3.hs -o /Users/mario/.stack/setup-exe-cache/aarch64-osx/tmp-Cabal-simple_CKvAmRb3_3.6.3.0_ghc-9.2.8
       Process exited with code: ExitFailure 1
$ echo $CC
clang
$ which `echo $CC`
/nix/store/wkadfwbhn9b4kdih88j7izzy20qw79bk-clang-wrapper-19.1.5/bin/clang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants