Skip to content

fix: Replicates SPM default behavior for publicHeadersPath: If this is nil, the directory is set to include #1429

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
12 changes: 6 additions & 6 deletions examples/pkg_manifest_minimal/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ swift_binary(
visibility = ["//visibility:public"],
deps = [
"//Sources/MyLibrary",
"@swiftpkg_my_local_package//:FarewellFramework",
"@swiftpkg_my_local_package//:GreetingsFramework",
"@swiftpkg_notthatamazingmodule//:NotThatAmazingModule",
"@swiftpkg_swift_argument_parser//:ArgumentParser",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ArgumentParser
import FarewellFramework
import GreetingsFramework
import MyLibrary
import NotThatAmazingModule
Expand All @@ -10,6 +11,8 @@ struct MyExecutable: AsyncParsableCommand {
print(namedGreeting.value)

let complexClass = ComplexClass(name: "Olivia", age: 30, favoriteColors: ["blue"])
print(complexClass.greet())
complexClass.greet()
let farewellMessage = FarewellFramework.myclang_get_farewell_message(MYCLANG_FAREWELL_GOODBYE)
print(String(cString: farewellMessage!))
}
}
1 change: 1 addition & 0 deletions examples/pkg_manifest_minimal/do_test
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ assert_match() {
output="$("${bazel}" run //Sources/MyExecutable)"
assert_match "Good morning, World!" "${output}"
assert_match "Olivia .* 30 years old" "${output}"
assert_match "Goodbye" "${output}"

# Run old-style executable in my_local_package
output="$("${bazel}" run @swiftpkg_my_local_package//:print-greeting)"
Expand Down
72 changes: 72 additions & 0 deletions examples/pkg_manifest_minimal/res_log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
name: //Sources/MyExecutable
kind: swift_binary
imports:
- ArgumentParser
- FarewellFramework
- GreetingsFramework
- MyLibrary
- NotThatAmazingModule
local_resolution:
- module: MyLibrary
label: //Sources/MyLibrary
external_resolution:
modules:
- ArgumentParser
- FarewellFramework
- GreetingsFramework
- NotThatAmazingModule
products:
- identity: my_local_package
name: FarewellFramework
label: '@swiftpkg_my_local_package//:FarewellFramework'
- identity: my_local_package
name: GreetingsFramework
label: '@swiftpkg_my_local_package//:GreetingsFramework'
- identity: notthatamazingmodule
name: NotThatAmazingModule
label: '@swiftpkg_notthatamazingmodule//:NotThatAmazingModule'
- identity: swift-argument-parser
name: ArgumentParser
label: '@swiftpkg_swift_argument_parser//:ArgumentParser'
unresolved: []
deps:
- //Sources/MyLibrary
- '@swiftpkg_my_local_package//:FarewellFramework'
- '@swiftpkg_my_local_package//:GreetingsFramework'
- '@swiftpkg_notthatamazingmodule//:NotThatAmazingModule'
- '@swiftpkg_swift_argument_parser//:ArgumentParser'
---
name: //Sources/MyLibrary
kind: swift_library
imports:
- GreetingsFramework
external_resolution:
modules:
- GreetingsFramework
products:
- identity: my_local_package
name: GreetingsFramework
label: '@swiftpkg_my_local_package//:GreetingsFramework'
unresolved: []
deps:
- '@swiftpkg_my_local_package//:GreetingsFramework'
---
name: //Tests/MyLibraryTests
kind: swift_test
imports:
- MyLibrary
- XCTest
builtins:
- XCTest
local_resolution:
- module: MyLibrary
label: //Sources/MyLibrary
external_resolution:
modules:
- XCTest
products: []
unresolved:
- XCTest
deps:
- //Sources/MyLibrary
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@ let package = Package(
name: "MyLocalPackage",
products: [
.executable(name: "print-greeting", targets: ["PrintGreeting"]),
.executable(name: "print-farewell", targets: ["PrintFarewell"]),
.library(
name: "GreetingsFramework",
targets: ["GreetingsFramework"]
),
.library(
name: "FarewellFramework",
targets: ["FarewellFramework"]
),
],
targets: [
// Puposefully, using the old-style pattern of a regular target being used by an executable
// product.
.target(
.executableTarget(
name: "PrintGreeting",
dependencies: ["GreetingsFramework"]
),
.executableTarget(
name: "PrintFarewell",
dependencies: ["FarewellFramework"]
),
.target(
name: "GreetingsFramework",
dependencies: []
),
.target(
name: "FarewellFramework",
dependencies: []
),
.testTarget(
name: "GreetingsFrameworkTests",
dependencies: ["GreetingsFramework"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef MYCLANG_LIBRARY_API_H
#define MYCLANG_LIBRARY_API_H

#ifdef __cplusplus
extern "C" {
#endif

/* Version information */
#define MYCLANG_VERSION_MAJOR 1
#define MYCLANG_VERSION_MINOR 0
#define MYCLANG_VERSION_PATCH 0

/* Maximum buffer sizes */
#define MYCLANG_MAX_NAME_LENGTH 256
#define MYCLANG_MAX_BUFFER_SIZE 4096

/* Status codes */
typedef enum {
MYCLANG_SUCCESS = 0,
MYCLANG_ERROR_INVALID_ARGUMENT = -1,
MYCLANG_ERROR_BUFFER_OVERFLOW = -2,
MYCLANG_ERROR_NOT_INITIALIZED = -3
} MyclangStatus;

/* Farewell message types */
typedef enum {
MYCLANG_FAREWELL_GOODBYE = 0,
MYCLANG_FAREWELL_PARTING = 1,
MYCLANG_FAREWELL_SEE_YOU_LATER = 2,
MYCLANG_FAREWELL_TAKE_CARE = 3,
MYCLANG_FAREWELL_ADIEU = 4,
MYCLANG_FAREWELL_DEPARTURE = 5
} MyclangFarewellType;

/* Data structures */
typedef struct {
char name[MYCLANG_MAX_NAME_LENGTH];
unsigned int id;
double value;
} MyclangObject;

/* Function declarations */
MyclangStatus myclang_initialize(void);
MyclangStatus myclang_cleanup(void);

MyclangStatus myclang_create_object(MyclangObject* obj,
const char* name,
unsigned int id,
double value);

MyclangStatus myclang_process_object(const MyclangObject* obj);

const char* myclang_get_version_string(void);

/* Farewell function */
const char* myclang_get_farewell_message(MyclangFarewellType type);

#ifdef __cplusplus
}
#endif

#endif /* MYCLANG_LIBRARY_API_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <string.h>
#include <stdio.h>
#include "MyClangLibrary/API.h"

static int g_initialized = 0;

MyclangStatus myclang_initialize(void) {
if (g_initialized) {
return MYCLANG_ERROR_INVALID_ARGUMENT;
}
g_initialized = 1;
return MYCLANG_SUCCESS;
}

MyclangStatus myclang_cleanup(void) {
if (!g_initialized) {
return MYCLANG_ERROR_NOT_INITIALIZED;
}
g_initialized = 0;
return MYCLANG_SUCCESS;
}

MyclangStatus myclang_create_object(MyclangObject* obj,
const char* name,
unsigned int id,
double value) {
if (!g_initialized) {
return MYCLANG_ERROR_NOT_INITIALIZED;
}

if (!obj || !name) {
return MYCLANG_ERROR_INVALID_ARGUMENT;
}

if (strlen(name) >= MYCLANG_MAX_NAME_LENGTH) {
return MYCLANG_ERROR_BUFFER_OVERFLOW;
}

strncpy(obj->name, name, MYCLANG_MAX_NAME_LENGTH - 1);
obj->name[MYCLANG_MAX_NAME_LENGTH - 1] = '\0';
obj->id = id;
obj->value = value;

return MYCLANG_SUCCESS;
}

MyclangStatus myclang_process_object(const MyclangObject* obj) {
if (!g_initialized) {
return MYCLANG_ERROR_NOT_INITIALIZED;
}

if (!obj) {
return MYCLANG_ERROR_INVALID_ARGUMENT;
}

// Example processing - in real implementation, this would do something useful
return MYCLANG_SUCCESS;
}

const char* myclang_get_version_string(void) {
static char version[32];
snprintf(version, sizeof(version), "%d.%d.%d",
MYCLANG_VERSION_MAJOR,
MYCLANG_VERSION_MINOR,
MYCLANG_VERSION_PATCH);
return version;
}

const char* myclang_get_farewell_message(MyclangFarewellType type) {
switch (type) {
case MYCLANG_FAREWELL_GOODBYE:
return "Goodbye";
case MYCLANG_FAREWELL_PARTING:
return "Parting";
case MYCLANG_FAREWELL_SEE_YOU_LATER:
return "See you later";
case MYCLANG_FAREWELL_TAKE_CARE:
return "Take care";
case MYCLANG_FAREWELL_ADIEU:
return "Adieu";
case MYCLANG_FAREWELL_DEPARTURE:
return "Departure";
default:
return "Goodbye";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import FarewellFramework

let message = FarewellFramework.myclang_get_farewell_message(MYCLANG_FAREWELL_SEE_YOU_LATER)

let swiftString = String(cString: message!)

print(swiftString)
Loading
Loading