esy is a package manager for Reason and OCaml. It's however possible to pull-in rust packages, if needed. Support for rust packages isn't natively available, there OCaml ecosystem does seem to bind to rust packages occasionally. If you wish to do so too, then here's how you can do it with esy.
- Create an esy manifest (
package.json
oresy.json
) with esy-rustup package.
{
"dependencies": {
"esy-rustup": "^1.51.1"
}
}
On newer MacOS, 1.75
is the recommended version, which is not published on NPM. You could use the github repository formula directly with,
"resolutions": {
"esy-rustup": "esy-packages/esy-rustup:esy.json#bd83f59efa55da39ba49b155d867e8ae55e3df1"
}
}
-
Run
cargo init
to initialize a rust project -
Run,
esy cargo run
to run the hello world program. -
If you're using
ocaml-rust
, you'll also need to setOCAML_WHERE_PATH
because of howocaml-rust
configures ocaml toolchain.
"esy": {
"buildEnv": {
"OCAML_WHERE_PATH": "#{ocaml.lib}/ocaml",
},
}
- Optionally add
#{self.root}/target/debug
toexportedEnv
and run the program withesy x rust-ocaml-with-esy
{
"exportedEnv": {
"PATH": {
"scope": "global",
"val": "#{self.root}/target/debug:$PATH"
}
}
}
cargo add
doesn't work with esy it hits the network and violates esy's sandbox assumptions. To workaround this,
- add crate to
Cargo.toml
manually
[dependencies]
rand = "0.8.5"
-
Run
esy cargo vendor
-
Build the project
esy
(which would runesy b cargo build
)