Skip to content

Example of rustc interface #621

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

Merged
merged 5 commits into from
Mar 21, 2020

Conversation

georgewfraser
Copy link
Contributor

@georgewfraser georgewfraser commented Mar 18, 2020

It's pretty hard to figure out how to use rustc_interface. This adds a simple "hello world" example of using rustc_interface to parse and typecheck a single file.

See discussion in https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982

mark-i-m
mark-i-m previously approved these changes Mar 19, 2020
Copy link
Member

@mark-i-m mark-i-m left a comment

Choose a reason for hiding this comment

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

@georgewfraser Thanks!

Could you split this into 2 PRs? The first to add the rustc-driver-example.rs and the second to add the link. That way the CI link check passes.

@JohnTitor
Copy link
Member

I'd like to create another directory and put .rs files there since I'd prefer src/ directory should contain markdown files or assets only, otherwise, it may make it hard that we find examples.

@eddyb
Copy link
Member

eddyb commented Mar 20, 2020

cc @Zoxc

@georgewfraser
Copy link
Contributor Author

@JohnTitor if you tell me what you want that directory to be named, I will set up 2 PRs, one with the example, one with the link.

let parse = queries.parse().unwrap().take();
println!("{:#?}", parse);
// Analyze the program and inspect the types of definitions.
queries.global_ctxt().unwrap().take().enter(|ctx| {
Copy link
Contributor

Choose a reason for hiding this comment

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

ctx should be named tcx here to match the compiler convention.

input_path: None,
// Option<PathBuf>
output_dir: None,
// Option<PathBuf>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure listing the types is very helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you know nothing about the compiler internals (like me!) it's quite helpful for understanding what each of these options actually does.

@JohnTitor
Copy link
Member

@georgewfraser examples or something else would be fine. Anyway we can rename it later.

@georgewfraser
Copy link
Contributor Author

OK @mark-i-m this is just the .rs file now, once this is merged I will make a new PR with the changes to the .md file.

Copy link
Member

@mark-i-m mark-i-m left a comment

Choose a reason for hiding this comment

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

Thank you!

@JohnTitor JohnTitor merged commit e74b303 into rust-lang:master Mar 21, 2020
georgewfraser added a commit to georgewfraser/rustc-dev-guide that referenced this pull request Mar 22, 2020
georgewfraser added a commit to georgewfraser/rustc-dev-guide that referenced this pull request Mar 22, 2020
mark-i-m pushed a commit that referenced this pull request Mar 22, 2020
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.

5 participants