-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
rustc should support compiling C code #1862
Copy link
Copy link
Closed
Labels
A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Metadata
Metadata
Assignees
Labels
A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The metaticket is #1850.
Summary: rustc should provide some external means of compiling C files as part of a crate, and referring to it later. Two possible options are:
Just make
rustcaccept.cfiles and compile them appropriately.Add an
externalattribute that describes a set of.cfiles and other options that a crate depends on.I am a fan of 2, particularly because I think it could go well with
#[cfg]and it means the rustc driver doesn't have to do stuff like throw options at the C compiler or something.So I have
foo.rc, that has some modules, but I can say:This makes it easy to compile a lot of C code directly inline with the crate. rustc just handles it in the backend. I feel this is the right approach since
rustcmay also be aware of other necessary flags, like if you should compile the.cfiles with-fPICor not.Furthermore, according to @brson in #1850, native modules do not strictly have to refer to shared libraries, and instead can use
nolinkas an attribute. I haven't tried, but perhaps right now it might look like:where
c_foo_baris the externally visible symbol name, that refers to part of the C code you're compiling. Alternatively the module declaration could have some other attribute; I'm not sure ifnolinkseems to make a lot of sense considering this is a clear use case, but it's not a huge deal here.Thoughts?