BitBoxSwiss / bitbox02-firmware

Firmware code of the BitBox02 hardware wallet
https://bitbox.swiss/bitbox02
Apache License 2.0
264 stars 95 forks source link

Add rust-analyzer to dev dockerfile #963

Closed NickeZ closed 1 month ago

NickeZ commented 2 years ago

This setup works for me, unless I'm being confused. I configure vim to run ra.sh and I start vim in the src/rust directory.

benma commented 2 years ago

Even in the bitbox02-rust crate, which depends on the C stuff?

I've been meaning to look into https://github.com/digitalbitbox/bitbox02-firmware/pull/819 again - if that one works, is this one still needed?

NickeZ commented 2 years ago

yeah, I tried the lsp hover function on some stuff and it seems to work everywhere.

This has a different approach to the other PR. In the other PR I tried to make RA work on the developers machine. In this PR RA is run in the docker container. So this PR is much smaller and easier to maintain I would say. The drawback of this approach is that you need to configure your editor to call ra.sh instead of rust-analyzer for this specific project. In vim I can just have a local vimrc file in the project folder. So it isn't a problem. Not sure how you do in Emacs.

benma commented 2 years ago

A bit confused, why does rust-analyzer need to run inside Docker, is there anything special inside the Docker container? Could it also run on the host?

Asking because adding it to the Dockerfile has at least these downsides:

NickeZ commented 2 years ago

rust-analyzer is technically a compiler, so it requires almost everything that you have in the docker container. The only way to make it work outside the container is to install most of those dependencies on your dev machine.

edit: It doesn't to the linking step. But it has to do all the other steps (e.g., macro expansion, type resolution, run build scripts) to create the autocompletions.

benma commented 2 years ago

Most of the deps means just the Rust toolchain or more? Cause installing the Rust stuff is not a big barrier imo.

I tried getting this PR to work in my environment, no luck yet. Will try again.

NickeZ commented 2 years ago

I don't remember exactly, but you need to be able to generate C headers, rust bindings. If you look at the other PR you can see that there are some changes so that the build scripts can detect if they are run under cmake or not.