Skip to content

Set up a client-side C library to talk with C APIs exposed from the compiler #381

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

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.15.1)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

project(SwiftDriver LANGUAGES Swift)
project(SwiftDriver LANGUAGES Swift C)

set(SWIFT_VERSION 5)
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
Expand All @@ -19,6 +19,9 @@ if(CMAKE_VERSION VERSION_LESS 3.16)
set(CMAKE_LINK_LIBRARY_FLAG "-l")
endif()

# ensure Swift compiler can find _CSwiftDriver
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/_CSwiftDriver/include>)

set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows)
Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ let package = Package(
targets: ["SwiftDriverExecution"]),
],
targets: [
.target(name: "_CSwiftDriver"),

/// The driver library.
.target(
name: "SwiftDriver",
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto", "Yams"]),
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto", "Yams", "_CSwiftDriver"]),

/// The execution library.
.target(
Expand Down
1 change: 1 addition & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_subdirectory(_CSwiftDriver)
add_subdirectory(SwiftOptions)
add_subdirectory(SwiftDriver)
add_subdirectory(SwiftDriverExecution)
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ target_link_libraries(SwiftDriver PUBLIC
SwiftOptions)
target_link_libraries(SwiftDriver PRIVATE
CYaml
Yams)
Yams
CSwiftDriver)

set_property(GLOBAL APPEND PROPERTY SWIFTDRIVER_EXPORTS SwiftDriver)

Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TSCBasic
import TSCUtility
import Foundation
import SwiftOptions
@_implementationOnly import _CSwiftDriver

/// The Swift driver.
public struct Driver {
Expand Down
10 changes: 10 additions & 0 deletions Sources/_CSwiftDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(CSwiftDriver STATIC
_CSwiftDriverImpl.c)
1 change: 1 addition & 0 deletions Sources/_CSwiftDriver/_CSwiftDriverImpl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file is here to prevent the package manager from warning about a target with no sources.
9 changes: 9 additions & 0 deletions Sources/_CSwiftDriver/include/_CSwiftDriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for Swift project authors

void dummyfunction();
4 changes: 4 additions & 0 deletions Sources/_CSwiftDriver/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module _CSwiftDriver {
umbrella "."
export *
}