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

WIP: feat(doc): Add a doc for beginners #474

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions doc/for-beginners.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Enable full `rust-analyzer` support of `cg_gcc` for your editor

## Steps to Follow
1. (Already done in by project.) Add the following lines to `Cargo.toml`
```toml
[package.metadata.rust-analyzer]
rustc_private = true
```
2. Install rust-src with rustup: `rustup component add rust-src`.
NOTE: Make sure you've switched to the corresponding toolchain as is used by cg_gcc
3. Set the lsp option `rust-analyzer.rustc.source = "discover"` (you can also set it to an explicit path), depending on your editor.
1. Neovim(nvim-lspconfig):
Copy link
Member

Choose a reason for hiding this comment

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

Please drop this part, there are a lot of IDEs, adding docs for some of them is not useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote this part for this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my point of view, it may be trivial for us that these steps are necessary, but probably harder for others to figure it out. Adding this may potentially add to contributors(since we only have no more than 100 developers).

```
require('lspconfig').rust_analyzer.setup{
settings = {
['rust-analyzer'] = {
-- add this section
rustc = {
source = "discover",
},
},
},
}
```
2. Emacs: customize `Lsp Rust Analyzer Rustc Source` to the Path `discover`

## FAQ

### Why is this needed?

Without these steps, `rust-analyzer` will NOT import `rustc` related packages to its scope and all rustc related clauses will fail to be analyzed in lsp, and the analyzer will notify you of the missing `rustc_*` packages.

### Why is this NOT needed for `rustc_codegen_llvm` in your `rust-src`?
In the `Cargo.toml` of the `rustc_codegen_llvm`, you may notice the following lines:
```toml
rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" }
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_fs_util = { path = "../rustc_fs_util" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_llvm = { path = "../rustc_llvm" }
rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_middle = { path = "../rustc_middle" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
```
They set the paths to the rustc-related packages, solving the problem of `rustc_private` packages.

In theory, it is possible that you use the same workaround as in `rustc_codegen_llvm`.

While the `rustc_codegen_cranelift` uses the same approach as `rustc_codegen_gcc`.

```
[package.metadata.rust-analyzer]
rustc_private = true
```

# Compiling External Project with `rustc_codegen_gcc`

1. Run the program with (in the root dir of `rustc_codegen_gcc` )(where `--manifest-path` is the path to the `Cargo.toml` of the project to run `cargo` against):

```shell
./y.sh cargo --manifest-path="..."
Copy link
Member

Choose a reason for hiding this comment

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

No need for the indent.

```

or you may as well add this alias in your `.bash_aliases`:
Copy link
Member

Choose a reason for hiding this comment

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

I'd drop this whole part. I never used .bash_aliases, only .bashrc for example. Having something so specific seems a bit too much imo.



```shell
alias cargcc="/path/to/rustc_codegen_gcc/y.sh cargo"
Copy link
Member

Choose a reason for hiding this comment

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

No need for the indent.

```

2. If std or libcore is needed, then the sysroot should be built first(see `build_system/src/test.rs` for hint.)
Loading