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

Support for building executables #46

Closed
jansegre opened this issue Jun 21, 2015 · 5 comments
Closed

Support for building executables #46

jansegre opened this issue Jun 21, 2015 · 5 comments

Comments

@jansegre
Copy link

I can create a pull request for this, but I wanted to discuss it first.

In some situations I find myself writing small C programs to generate Rust files with const's taken from header defines. For such it would practical to reuse gcc-rs abstractions over a C compiler.

Therefore, I propose a compile_exectuable function and to change Config::compile behavior to detect whether to build an executable or a lib based on the simple pattern, lib.so* for a library, and "not . and not lib*" for executable.

@alexcrichton
Copy link
Member

Unfortunately this doesn't quite play well with this crate's cross compilation story. If you want to get the value of a #define for the target, you need to compile an executable for the target but you may not be able to run it.

@jansegre
Copy link
Author

Hmm, I hadn't thought of that. I can see it getting messy if the executable
target is always native, specially because defines are usually dependant on
the target.

Maybe the most universal way for automatic defines extraction is closer to
bindgen.

Anyway I still consider the option to fork gcc-rs to provide only
executable generation without cross compilation support. Though that may
not be a good practice overall seems better than hard invoking cc and
compiled commands, in a way that will definitely not work on Windows.

On Sun, Jun 21, 2015, 15:20 Alex Crichton notifications@github.com wrote:

Unfortunately this doesn't quite play well with this crate's cross
compilation story. If you want to get the value of a #define for the
target, you need to compile an executable for the target but you may not be
able to run it.


Reply to this email directly or view it on GitHub
#46 (comment).

@alexcrichton
Copy link
Member

This crate could certainly provide the ability to build executables, but I think I'd prefer to not do so as it's not something that should be relied upon. That being said, if this crate could facilitate you in emitting a binary, feel free to open an issue!

@oli-obk
Copy link

oli-obk commented Oct 21, 2015

on a side-note for anyone reaching this issue: You can use this crate to create executables quite easily:

let mut gcc = gcc::Config::new();
gcc.cpp(true);
gcc.include(".");
let mut cmd = gcc.get_compiler().to_command();
cmd.arg("main.cpp");
assert!(cmd.status().unwrap().success());

@teythoon
Copy link

I'd appreciate proper support for creating executables as well. Our use case is that we have a crate with a C API that we want to compile tests for. We wouldn't mind building for the target and not for the build host if we are cross-compiling.

Currently, we invoke make and rely on the compiler understanding -lsomething and friends, which obviously does not fly with VS.

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

No branches or pull requests

4 participants