-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add .staticLibrary
support for binary targets
#8639
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swift-tools-version: 6.0 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Package1", | ||
targets: [ | ||
.executableTarget( | ||
name: "Example", | ||
dependencies: [ | ||
"Simple", | ||
"Wrapper" | ||
] | ||
), | ||
.target( | ||
name: "Wrapper", | ||
dependencies: [ | ||
"Simple" | ||
] | ||
), | ||
.binaryTarget( | ||
name: "Simple", | ||
path: "Simple.artifactbundle" | ||
), | ||
] | ||
) |
87 changes: 87 additions & 0 deletions
87
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
SRC_FILES := $(wildcard *.c) | ||
|
||
# Define architectures and platforms | ||
ARCHS := x86_64 arm64 | ||
PLATFORMS := macos linux | ||
|
||
# Define output directories | ||
BUILD_DIR := build | ||
DIST_DIR := dist | ||
|
||
# Platform-specific settings | ||
MACOS_SDK := $(shell xcrun --sdk macosx --show-sdk-path 2>/dev/null || echo "") | ||
MACOS_MIN_VERSION := 10.15 | ||
|
||
# Compiler flags | ||
COMMON_FLAGS := -O2 | ||
|
||
# Platform and architecture specific flags | ||
MACOS_X86_64_FLAGS := -target x86_64-apple-macos$(MACOS_MIN_VERSION) -isysroot $(MACOS_SDK) | ||
MACOS_ARM64_FLAGS := -target arm64-apple-macos$(MACOS_MIN_VERSION) -isysroot $(MACOS_SDK) | ||
LINUX_X86_64_FLAGS := -target x86_64-unknown-linux-gnu | ||
LINUX_ARM64_FLAGS := -target aarch64-unknown-linux-gnu | ||
|
||
.PHONY: all clean macos linux universal | ||
|
||
all: macos linux | ||
|
||
# Create necessary directories | ||
$(BUILD_DIR): | ||
mkdir -p $(BUILD_DIR)/macos/x86_64 | ||
mkdir -p $(BUILD_DIR)/macos/arm64 | ||
mkdir -p $(BUILD_DIR)/linux/x86_64 | ||
mkdir -p $(BUILD_DIR)/linux/arm64 | ||
|
||
$(DIST_DIR): | ||
mkdir -p $(DIST_DIR)/macos | ||
mkdir -p $(DIST_DIR)/linux | ||
|
||
# macOS x86_64 build | ||
$(BUILD_DIR)/macos/x86_64/%.o: %.c | $(BUILD_DIR) | ||
clang $(COMMON_FLAGS) $(MACOS_X86_64_FLAGS) -c -o $@ $< | ||
|
||
# macOS arm64 build | ||
$(BUILD_DIR)/macos/arm64/%.o: %.c | $(BUILD_DIR) | ||
clang $(COMMON_FLAGS) $(MACOS_ARM64_FLAGS) -c -o $@ $< | ||
|
||
# Linux x86_64 build | ||
$(BUILD_DIR)/linux/x86_64/%.o: %.c | $(BUILD_DIR) | ||
clang $(COMMON_FLAGS) $(LINUX_X86_64_FLAGS) -c -o $@ $< | ||
|
||
# Linux arm64 build | ||
$(BUILD_DIR)/linux/arm64/%.o: %.c | $(BUILD_DIR) | ||
clang $(COMMON_FLAGS) $(LINUX_ARM64_FLAGS) -c -o $@ $< | ||
|
||
# Define object files for each platform and architecture | ||
MACOS_X86_64_OBJ_FILES := $(patsubst %.c,$(BUILD_DIR)/macos/x86_64/%.o,$(SRC_FILES)) | ||
MACOS_ARM64_OBJ_FILES := $(patsubst %.c,$(BUILD_DIR)/macos/arm64/%.o,$(SRC_FILES)) | ||
LINUX_X86_64_OBJ_FILES := $(patsubst %.c,$(BUILD_DIR)/linux/x86_64/%.o,$(SRC_FILES)) | ||
LINUX_ARM64_OBJ_FILES := $(patsubst %.c,$(BUILD_DIR)/linux/arm64/%.o,$(SRC_FILES)) | ||
|
||
# Create individual architecture libraries | ||
$(DIST_DIR)/macos/libSimple_x86_64.a: $(MACOS_X86_64_OBJ_FILES) | $(DIST_DIR) | ||
llvm-ar rc $@ $^ | ||
|
||
$(DIST_DIR)/macos/libSimple_arm64.a: $(MACOS_ARM64_OBJ_FILES) | $(DIST_DIR) | ||
llvm-ar rc $@ $^ | ||
|
||
$(DIST_DIR)/linux/libSimple_x86_64.a: $(LINUX_X86_64_OBJ_FILES) | $(DIST_DIR) | ||
llvm-ar rc $@ $^ | ||
|
||
$(DIST_DIR)/linux/libSimple_arm64.a: $(LINUX_ARM64_OBJ_FILES) | $(DIST_DIR) | ||
llvm-ar rc $@ $^ | ||
|
||
# Create universal binary for macOS | ||
$(DIST_DIR)/macos/libSimple.a: $(DIST_DIR)/macos/libSimple_x86_64.a $(DIST_DIR)/macos/libSimple_arm64.a | ||
lipo -create -output $@ $^ | ||
|
||
# For Linux, we'll provide separate libraries since lipo is macOS-specific | ||
linux: $(DIST_DIR)/linux/libSimple_x86_64.a $(DIST_DIR)/linux/libSimple_arm64.a | ||
@echo "Linux libraries built in $(DIST_DIR)/linux/" | ||
@echo "Note: For Linux, use the architecture-specific libraries as needed." | ||
|
||
macos: $(DIST_DIR)/macos/libSimple.a | ||
@echo "macOS universal library built at $(DIST_DIR)/macos/libSimple.a" | ||
|
||
clean: | ||
rm -rf $(BUILD_DIR) $(DIST_DIR) |
Binary file added
BIN
+1.21 KB
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/dist/linux/libSimple_arm64.a
Binary file not shown.
Binary file added
BIN
+1.14 KB
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/dist/linux/libSimple_x86_64.a
Binary file not shown.
Binary file added
BIN
+1.49 KB
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/dist/macos/libSimple.a
Binary file not shown.
Binary file added
BIN
+688 Bytes
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/dist/macos/libSimple_arm64.a
Binary file not shown.
Binary file added
BIN
+792 Bytes
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/dist/macos/libSimple_x86_64.a
Binary file not shown.
1 change: 1 addition & 0 deletions
1
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/include/simple.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int foo(void); |
4 changes: 4 additions & 0 deletions
4
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/include/simple.modulemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Simple { | ||
header "simple.h" | ||
export * | ||
} |
35 changes: 35 additions & 0 deletions
35
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/info.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"schemaVersion": "1.0", | ||
"artifacts": { | ||
"simple": { | ||
"type": "staticLibrary", | ||
"version": "1.0.0", | ||
"variants": [ | ||
{ | ||
"path": "dist/macOS/libSimple.a", | ||
"supportedTriples": ["arm64-apple-macosx", "x86_64-apple-macosx"], | ||
"staticLibraryMetadata": { | ||
"headerPaths": ["include"], | ||
"moduleMapPath": "include/simple.modulemap" | ||
} | ||
}, | ||
{ | ||
"path": "dist/linux/libSimple_arm64.a", | ||
"supportedTriples": ["aarch64-unknown-linux-gnu"], | ||
"staticLibraryMetadata": { | ||
"headerPaths": ["include"], | ||
"moduleMapPath": "include/simple.modulemap" | ||
} | ||
}, | ||
{ | ||
"path": "dist/linux/libSimple_x86_64.a", | ||
"supportedTriples": ["x86_64-unknown-linux-gnu"], | ||
"staticLibraryMetadata": { | ||
"headerPaths": ["include"], | ||
"moduleMapPath": "include/simple.modulemap" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/simple.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int foo(void) { return 42; } |
10 changes: 10 additions & 0 deletions
10
Fixtures/BinaryLibraries/Static/Package1/Sources/Example/Example.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Simple | ||
import Wrapper | ||
|
||
@main | ||
struct Example { | ||
static func main() { | ||
print(foo()) | ||
print(bar()) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Fixtures/BinaryLibraries/Static/Package1/Sources/Wrapper/include/wrapper.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int bar(void); |
3 changes: 3 additions & 0 deletions
3
Fixtures/BinaryLibraries/Static/Package1/Sources/Wrapper/wrapper.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "simple.h" | ||
|
||
int bar(void) { return foo(); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.