I have the library version of ChucK I want to compile into the crate. Bindings are generated from c_chuck.h, a C wrapper for ChucK classes and stuff. The problem I'm running into is that ChucK has both .c and .cpp files that need to be compiled to objects, and then linked into libchuck.a or libchuck.so on Linux. As far as I can tell, cc-rs has a .cpp(true) option that enables C++ compilation, but once it's set it applies to all included files. Thus cargo build fails because the build.rs is trying to compile .c files w/ g++. Is there a good example of a build.rs that successfully handles compiling both .c and .cpp object files and linking them in a static/dynamic library?
Here's the relevant code from build.rs:
let mut builder = cc::Build::new();
builder.include("./src");
builder.include("./src/core");
builder.include("./src/core/lo");
builder.include("./src/core/regex");
builder.include("./src/host");
builder.include("./src/host/RtAudio");
builder.flag_if_supported("-B");
builder.flag_if_supported("--sysroot");
builder.flag_if_supported("-D__PLATFORM_LINUX__");
builder.flag_if_supported("-DHAVE_CONFIG_H");
builder.flag_if_supported("-DHAVE_POLL");
builder.flag_if_supported("-DHAVE_LIBPTHREAD");
builder.flag_if_supported("-DENABLE_THREADS");
builder.flag_if_supported("-D__CK_SNDFILE_NATIVE__");
builder.flag_if_supported("-D__LINUX_ALSA__");
builder.flag_if_supported("-DUSE_ALSA");
builder.flag_if_supported("-DUSE_DLTRICK_ALSA");
builder.flag_if_supported("-fPIC");
builder.flag_if_supported("-fno-strict-aliasing");
builder.flag_if_supported("-fstacore-protector-strong");
builder.flag_if_supported("-fno-plt");
builder.flag_if_supported("-fpermissive");
builder.flag_if_supported("-O3");
builder.flag_if_supported("-mtune=generic");
builder.flag_if_supported("-march=native");
builder.flag_if_supported("-pipe");
builder.file("./src/core/util_math.c");
builder.file("./src/core/util_network.c");
builder.file("./src/core/util_raw.c");
builder.file("./src/core/util_sndfile.c");
builder.file("./src/core/util_xforms.c");
builder.cpp(true);
builder.cpp_link_stdlib("stdc++");
builder.file("./src/c_chuck.cpp"); // C wrapper
builder.file("./src/core/chuck_absyn.cpp");
builder.file("./src/core/chuck_carrier.cpp");
builder.file("./src/core/chuck_compile.cpp");
builder.file("./src/core/chuck_dl.cpp");
builder.file("./src/core/chuck_emit.cpp");
builder.file("./src/core/chuck_errmsg.cpp");
builder.file("./src/core/chuck_frame.cpp");
builder.file("./src/core/chuck_instr.cpp");
builder.file("./src/core/chuck_io.cpp");
builder.file("./src/core/chuck_lang.cpp");
builder.file("./src/core/chuck_oo.cpp");
builder.file("./src/core/chuck_otf.cpp");
builder.file("./src/core/chuck_parse.cpp");
builder.file("./src/core/chuck_scan.cpp");
builder.file("./src/core/chuck_shell.cpp");
builder.file("./src/core/chuck_stats.cpp");
builder.file("./src/core/chuck_symbol.cpp");
builder.file("./src/core/chuck_table.cpp");
builder.file("./src/core/chuck_type.cpp");
builder.file("./src/core/chuck_ugen.cpp");
builder.file("./src/core/chuck_utils.cpp");
builder.file("./src/core/chuck_vm.cpp");
builder.file("./src/core/chuck.cpp");
builder.file("./src/core/hidio_sdl.cpp");
builder.file("./src/core/midiio_rtmidi.cpp");
builder.file("./src/core/rtmidi.cpp");
builder.file("./src/core/uana_extract.cpp");
builder.file("./src/core/uana_xform.cpp");
builder.file("./src/core/ugen_filter.cpp");
builder.file("./src/core/ugen_osc.cpp");
builder.file("./src/core/ugen_stk.cpp");
builder.file("./src/core/ugen_xxx.cpp");
builder.file("./src/core/ulib_machine.cpp");
builder.file("./src/core/ulib_math.cpp");
builder.file("./src/core/ulib_opsc.cpp");
builder.file("./src/core/ulib_regex.cpp");
builder.file("./src/core/ulib_std.cpp");
builder.file("./src/core/util_buffers.cpp");
builder.file("./src/core/util_console.cpp");
builder.file("./src/core/util_hid.cpp");
builder.file("./src/core/util_opsc.cpp");
builder.file("./src/core/util_serial.cpp");
builder.file("./src/core/util_string.cpp");
builder.file("./src/core/util_thread.cpp");
#[cfg(feature = "static")]
builder.compile("libchuck.a");
#[cfg(feature = "dynamic")]
builder.compile("libchuck.so")
And here's the entire build.rs file for reference and context: build.rs
I am new to all of this so any helpful pointers and constructive criticism is most welcome.