-
Notifications
You must be signed in to change notification settings - Fork 253
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
support c2rust <path/to/*.c>
in lieu of compile_commands.json
#1037
Conversation
ce017a6
to
36d8fd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly sane. Commented a few cleanups/improvements inline; the only user-significant one is to use a temporary directory for the generated compile_commands.json
.
Error messages could be more helpful, e.g. including paths and mentioning what the JSON file is for.
36d8fd0
to
026c19f
Compare
This probably should have some corresponding doc/diagnostics changes, e.g. the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we put this new logic in fn gen_compile_commands
and not need to write a temporary compile_commands.json
to disk?
c2rust/c2rust-transpile/src/compile_cmds/mod.rs
Lines 171 to 176 in c603b25
/// Read `compile_commands` file, optionally ignore any entries not matching | |
/// `filter`, and filter out any .S files since they're likely assembly files. | |
pub fn get_compile_commands( | |
compile_commands: &Path, | |
filter: &Option<Regex>, | |
) -> Result<Vec<LinkCmd>, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the CLI is agreed upon, don't forget to update the readme.
I too think it would be cleaner to make As an aside, there appears to be an existing project that could be leveraged though I am not sure if it makes sense: https://github.com/rizsotto/json_compilation_db |
☝️
I think the existing c2rust/c2rust-transpile/src/compile_cmds/mod.rs Lines 12 to 33 in c603b25
json_compilation_db does.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another suggestion I thought of: most clang
tooling that I've seen that accepts compilation databases (e.x. clang-tidy
) also accepts a list of files as normal arguments, and then after --
, a list of cflags that applies to all of those files and would go after the clang <file>
in the command
/arguments
. Following that I think would be best for compatibility and familiarity, and is also a bit more flexible since it allows for other arguments (albeit the same ones for every file).
@thedataking @kkysen thoughts on 6c497c7? The new interface would either be providing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to look at the interface with clang
we're using. I'm still not sure why we have to create a temporary compile commands. If we do, though, I think we should use the tempfile
crate to do so, as that deletes the file on destruction, so it will get deleted if we panic or return early in between, which very well may happen. Also, the clap CLI seems okay, but I think it'd be better if we can match clang tooling's API for specifying either a compile commands or a list of sources and a list of flags/other arguments, which is more flexible and consistent with existing tooling.
@kkysen this is a reasonable line of thought but it would expand the scope of the task beyond what was planned. This PR to narrowly resolve the feature request in #1033 as it already turned out to be more work than expected. Edited to acknowledge the merit of the idea being proposed. |
PR #1033 asked if we could accept source files instead of a This PR has received more work and review than I expected. I'd like it to be wrapped up in the simplest possible way that satisfied the original goals and doesn't break or extend the existing interface (unless we must). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Should we update the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after that path canonicalization comment. I still think there are ways to improve how we do this, but this is a good and simple start to it that should be good for now.
This adds support for transpiling C sources without needing to generate a
compile_commands.json
with something such asbear
orcmake
. The way it works is that a temporarytemp_compile_commands
file is created. One alternative to this approach would have been to alter the AST exporter to use aFixedCompilationDatabase
but it seemed simpler to support this feature from the front end.