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

Tutorial: Rust FFI in Haskell #24

Merged
merged 33 commits into from
Apr 2, 2024
Merged

Tutorial: Rust FFI in Haskell #24

merged 33 commits into from
Apr 2, 2024

Conversation

shivaraj-bh
Copy link
Member

@shivaraj-bh shivaraj-bh commented Feb 17, 2024

preview:

nix run github:nixos-asia/website/haskell-rust-ffi#preview -- --port 5555
open http://localhost:5555/en/haskell-rust-ffi

@shivaraj-bh
Copy link
Member Author

I wanted to write a blog post about this, rather than publishing it as a tutorial in either community.flake.parts or here, as I wanted to describe the entire process, as I debugged, in the form of a story.

@srid
Copy link
Member

srid commented Mar 26, 2024

Is this still being written?

You also want to,

@shivaraj-bh
Copy link
Member Author

Is this still being written?

Yes, I have to resume work on this

@srid
Copy link
Member

srid commented Mar 26, 2024

Associated repo (I think): https://github.com/shivaraj-bh/haskell-rust-ffi-template

Additionally change the introduction to be more tutorial-like and add the rust library section.

Also, add placeholders for other sections.
@shivaraj-bh
Copy link
Member Author

It is more appropriate as a tutorial series under Nix for development, so I have made the necessary changes and added placeholders, will be filling them up soon.

@shivaraj-bh shivaraj-bh marked this pull request as ready for review March 28, 2024 11:12
@shivaraj-bh shivaraj-bh changed the title Using rust library as a haskell dependency Tutorial: Rust FFI in Haskell Mar 28, 2024
Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

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

LGTM, after these changes.

en/haskell-rust-ffi.md Outdated Show resolved Hide resolved
Comment on lines 57 to 59
nixpkgs_url="github:nixos/nixpkgs/$(nix flake metadata --json | nix run nixpkgs#jq -- '.locks.nodes.nixpkgs.locked.rev' -r)" && \
nix shell $nixpkgs_url#cabal-install $nixpkgs_url#ghc -c \
cabal init -n --exe -m --simple hello-haskell
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nixpkgs_url="github:nixos/nixpkgs/$(nix flake metadata --json | nix run nixpkgs#jq -- '.locks.nodes.nixpkgs.locked.rev' -r)" && \
nix shell $nixpkgs_url#cabal-install $nixpkgs_url#ghc -c \
cabal init -n --exe -m --simple hello-haskell
nix shell nixpkgs#ghc nixpkgs#cabal-install -c cabal -- init -n --exe -m --simple hello-haskell

Copy link
Member Author

Choose a reason for hiding this comment

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

This will break the further steps in the tutorial, as we are assuming that the .cabal file generated by cabal-install in flake:nixpkgs will work with the nixpkgs input of the flake in the tutorial.

This was the initial command, but when I was following along the tutorial it fails, as constraints on base depends on GHC version, which can be different based on the nixpkgs commit. I doubt there is a way to cabal init without any constraints on the base package.

Copy link
Member

Choose a reason for hiding this comment

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

Pass -d base option?

❯ nix shell nixpkgs#ghc nixpkgs#cabal-install -c cabal -- init -n --exe -m --simple -d base --overwrite
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.
[Log] Using cabal specification: 3.0
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] CHANGELOG.md already exists. Backing up old version in CHANGELOG.md.save0
[Log] Overwriting file CHANGELOG.md...
[Log] app already exists. Backing up old version in app.save1
[Log] Overwriting directory ./app...
[Log] Creating fresh file app/Main.hs...
[Log] hello-haskell.cabal already exists. Backing up old version in hello-haskell.cabal.save0
[Log] Overwriting file hello-haskell.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.


srid on appreciate.intern /tmp/hello-haskell via λ
❯ rg base *.cabal
14:    build-depends:    base

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

en/haskell-rust-ffi.md Outdated Show resolved Hide resolved
en/haskell-rust-ffi.md Outdated Show resolved Hide resolved
en/haskell-rust-ffi.md Outdated Show resolved Hide resolved
en/haskell-rust-ffi.md Outdated Show resolved Hide resolved
en/haskell-rust-ffi.md Outdated Show resolved Hide resolved
shivaraj-bh and others added 9 commits April 2, 2024 12:01
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
@srid srid merged commit 80562b1 into master Apr 2, 2024
2 checks passed
@srid
Copy link
Member

srid commented Apr 2, 2024

@shivaraj-bh Feel free to announce in https://twitter.com/nixos_asia, Zulip, and elsewhere as you see fit.

@srid srid deleted the haskell-rust-ffi branch April 2, 2024 20:25
@shivaraj-bh
Copy link
Member Author

I probably should’ve linked this earlier here, but I was waiting on this before merging: srid/haskell-flake#283 (comment)

@srid
Copy link
Member

srid commented Apr 2, 2024

Okay let's announce it after I fix that issue.

@shivaraj-bh
Copy link
Member Author

@srid could you generate an image for this article?

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