-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add basic support for building C via swiftpm #183
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
Conversation
@@ -0,0 +1,6 @@ | |||
int foo() { |
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.
'Clang' is spelled with a lowercase 'l'.
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.
Actually I wanted to name it CModules but CModules refers to system libraries having a modulemaps as a wrapper. so I changed it to C Lang which spelled CLang lol, but anyway Clang would make perfect sense here too. Changing.
2e79aec
to
a65e1b1
Compare
Looks like a great start and really: great job getting this going. I'll review it more thoroughly in the morning. |
OMG awesome! Will review ASAP |
Overall seems like a great start to me. There are a couple things I'd like to see fixed before merge (mostly having to do with erroring out on unsupported things, or not erroring out on things which do work but aren't yet complete (like not require the module.modulemap to be written, even though we don't synthesize it yet)), but once @mxcl is happy with it I'd be glad to see it go in and then build in the other things like module map synthesis or incremental build support. |
@ddunbar I think I was able to resolve almost all of the things pointed by you. You can re-review the changes here: https://github.com/apple/swift-package-manager/pull/183/files |
|
||
var args: [String] = [] | ||
#if os(Linux) | ||
args += ["-fPIC"] |
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.
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.
That is probably correct behavior, I would want to test it with Swift interop to know for sure.
On Mar 10, 2016, at 11:04 AM, Ankit Agarwal [email protected] wrote:
In Sources/Build/describe().swift #183 (comment):
//if it not present
if !module.moduleMapPath.isFile {
try mkdir(module.moduleMapPath.parentDirectory)
try fopen(module.moduleMapPath, mode: .Write) { fp in
try fputs("\n", fp)
}
}
let inputs = module.dependencies.map{ $0.targetName } + module.sources.paths
let productPath = Path.join(prefix, "lib(module.c99name).so")
let wd = Path.join(prefix, "(module.c99name).build")
mkdirs.insert(wd)
var args: [String] = []
- #if os(Linux)
Tests were failing on linux and clang suggested to recompile using this. Not sure if this is correct? @mxcl https://github.com/mxcl @ddunbar https://github.com/ddunbarargs += ["-fPIC"]
—
Reply to this email directly or view it on GitHub https://github.com/apple/swift-package-manager/pull/183/files#r55731599.
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've tests in this PR calling c methods from swift.
Also I am waiting for a new toolchain to arrive before I resolve conflicts. Its just one small method rename I think. |
…le.modulemap` will be available inside a `include` directory, doesn't generates it automatically. Also creates only shared libraries and not executable for now.
I succeeded in building toolchain from latest masters and then use that for developing this. Now rebased correctly. 😬 |
@mxcl CI on this? though probably review first. |
Let's try it. @swift-ci please test |
Add basic support for building C via swiftpm
A key point in our evolution, many thanks everyone 👊🏻 |
Woot! |
😱😱 didn't expect a merge so soon. Thanks! It was fun doing this. Will try adding other remaining things from proposal😀 |
if !cSources.isEmpty { | ||
guard swiftSources.isEmpty else { throw Module.Error.MixedSources(path) } | ||
//FIXME: Support executables for C languages | ||
guard !cSources.contains({ $0.hasSuffix("main.c") }) else { throw Module.Error.CExecutableNotSupportedYet(path) } |
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.
Should check the basename.
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.
raised #199 for this
Fix Windows build with posix specific stat APIs
Basic implementation of proposal https://github.com/apple/swift-evolution/blob/master/proposals/0038-swiftpm-c-language-targets.md
include/module.modulemap
should be present for each C lang module.swift
and.c
, it will error out.module.modulemap
will be available inside ainclude
directory, doesn't generates it automatically.Remaining features will be added incrementally.