Skip to content

The sbt plugin should offer a way to compile C files #657

@jonas

Description

@jonas

It would be useful to allow application and libraries to drop down to C for parts of their implementation, for example to not be blocked by limitations such as the ability to pass structs by value. One example is bindgen which currently need a think C wrapper to use libclang. Another example would be to use a C++ library.

The sbt plugin should provide a setting or task which makes it possible to compile C files and include the resulting object files in the nativeCompileLL task used by the linker.

Example code from #642

nativeCompileLL += {
  val logger   = nativeLogger.value
  val cwd      = nativeWorkdir.value
  val compiler = nativeClang.value.getAbsolutePath
  val opts     = nativeCompileOptions.value
  val cpath    = (resourceDirectory in Compile).value / "clang.c"
  val opath    = (crossTarget in Compile).value / "clang.o"
  val compilec = Seq(compiler) ++ opts ++ Seq("-c",
                                              cpath.toString,
                                              "-o",
                                              opath.toString)

  val exitCode = Process(compilec, cwd) ! logger
  if (exitCode != 0) {
    println("Failed to compile " + cpath)
  }
  opath
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions