Skip to content

Commit c9f4f7f

Browse files
committed
compile xcframework so spm will work woo swift great language
1 parent 8f3dbf3 commit c9f4f7f

File tree

6 files changed

+188
-32
lines changed

6 files changed

+188
-32
lines changed

Makefile

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,22 @@ build-bridge:
3030
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -buildmode=c-archive -o libtsc_darwin_amd64.a .
3131
@echo "$(YELLOW)Building for macOS arm64...$(NC)"
3232
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -buildmode=c-archive -o libtsc_darwin_arm64.a .
33-
@echo "$(YELLOW)Building for iOS arm64...$(NC)"
34-
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=ios GOARCH=arm64 go build -buildmode=c-archive -o libtsc_ios_arm64.a .
35-
@echo "$(YELLOW)Building for iOS Simulator x86_64...$(NC)"
36-
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -buildmode=c-archive -tags ios -o libtsc_ios_sim_amd64.a .
37-
@echo "$(YELLOW)Building for iOS Simulator arm64...$(NC)"
38-
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -buildmode=c-archive -tags ios -o libtsc_ios_sim_arm64.a .
39-
@echo "$(YELLOW)Creating universal binary for macOS...$(NC)"
40-
@cd $(BRIDGE_DIR) && lipo -create libtsc_darwin_amd64.a libtsc_darwin_arm64.a -output libtsc_macos.a
41-
@echo "$(YELLOW)Creating universal binary for iOS Simulator...$(NC)"
42-
@cd $(BRIDGE_DIR) && lipo -create libtsc_ios_sim_amd64.a libtsc_ios_sim_arm64.a -output libtsc_ios_simulator.a
33+
@echo "$(YELLOW)Creating universal binary...$(NC)"
34+
@cd $(BRIDGE_DIR) && lipo -create libtsc_darwin_amd64.a libtsc_darwin_arm64.a -output libtsc_universal.a
35+
@echo "$(YELLOW)Creating XCFramework...$(NC)"
36+
@cd $(BRIDGE_DIR) && rm -rf TSCBridge.xcframework
37+
@cd $(BRIDGE_DIR) && mkdir -p headers && cp libtsc_darwin_amd64.h headers/tsc_bridge.h
38+
@cd $(BRIDGE_DIR) && xcodebuild -create-xcframework \
39+
-library libtsc_universal.a -headers headers \
40+
-output TSCBridge.xcframework
4341
@echo "$(YELLOW)Copying files to output directory...$(NC)"
44-
@cp $(BRIDGE_DIR)/libtsc_macos.a $(OUTPUT_DIR)/
45-
@cp $(BRIDGE_DIR)/libtsc_ios_arm64.a $(OUTPUT_DIR)/
46-
@cp $(BRIDGE_DIR)/libtsc_ios_simulator.a $(OUTPUT_DIR)/
42+
@cp -r $(BRIDGE_DIR)/TSCBridge.xcframework $(OUTPUT_DIR)/
4743
@cp $(BRIDGE_DIR)/libtsc_darwin_amd64.h $(OUTPUT_DIR)/tsc_bridge.h
4844
@echo "$(YELLOW)Creating module map...$(NC)"
4945
@echo 'module TSCBridge {\n header "tsc_bridge.h"\n export *\n}' > $(OUTPUT_DIR)/module.modulemap
5046
@echo "$(YELLOW)Cleaning up intermediate files...$(NC)"
51-
@cd $(BRIDGE_DIR) && rm -f libtsc_darwin_*.a libtsc_ios_*.a *.h
47+
@cd $(BRIDGE_DIR) && rm -f libtsc_*.a *.h
48+
@cd $(BRIDGE_DIR) && rm -rf TSCBridge.xcframework headers
5249
@echo "$(GREEN)C Bridge build completed successfully!$(NC)"
5350
@$(MAKE) verify-bridge
5451

@@ -57,33 +54,32 @@ build-bridge-macos:
5754
@echo "$(GREEN)Building TypeScript Go C Bridge for macOS only...$(NC)"
5855
@mkdir -p $(OUTPUT_DIR)
5956
@echo "$(YELLOW)Cleaning previous builds...$(NC)"
60-
@rm -f $(OUTPUT_DIR)/libtsc_macos.a $(OUTPUT_DIR)/tsc_bridge.h $(BRIDGE_DIR)/libtsc_*.a $(BRIDGE_DIR)/*.h
57+
@rm -f $(OUTPUT_DIR)/TSCBridge.xcframework $(OUTPUT_DIR)/tsc_bridge.h $(BRIDGE_DIR)/libtsc_*.a $(BRIDGE_DIR)/*.h
6158
@echo "$(YELLOW)Building for macOS x86_64...$(NC)"
6259
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -buildmode=c-archive -o libtsc_darwin_amd64.a .
6360
@echo "$(YELLOW)Building for macOS arm64...$(NC)"
6461
@cd $(BRIDGE_DIR) && CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -buildmode=c-archive -o libtsc_darwin_arm64.a .
65-
@echo "$(YELLOW)Creating universal binary for macOS...$(NC)"
66-
@cd $(BRIDGE_DIR) && lipo -create libtsc_darwin_amd64.a libtsc_darwin_arm64.a -output libtsc_macos.a
62+
@echo "$(YELLOW)Creating universal binary...$(NC)"
63+
@cd $(BRIDGE_DIR) && lipo -create libtsc_darwin_amd64.a libtsc_darwin_arm64.a -output libtsc_universal.a
6764
@echo "$(YELLOW)Copying files to output directory...$(NC)"
68-
@cp $(BRIDGE_DIR)/libtsc_macos.a $(OUTPUT_DIR)/
65+
@cp $(BRIDGE_DIR)/libtsc_universal.a $(OUTPUT_DIR)/
6966
@cp $(BRIDGE_DIR)/libtsc_darwin_amd64.h $(OUTPUT_DIR)/tsc_bridge.h
7067
@echo "$(YELLOW)Creating module map...$(NC)"
7168
@echo 'module TSCBridge {\n header "tsc_bridge.h"\n export *\n}' > $(OUTPUT_DIR)/module.modulemap
7269
@echo "$(YELLOW)Cleaning up intermediate files...$(NC)"
73-
@cd $(BRIDGE_DIR) && rm -f libtsc_darwin_*.a *.h
70+
@cd $(BRIDGE_DIR) && rm -f libtsc_*.a *.h
7471
@echo "$(GREEN)C Bridge macOS build completed successfully!$(NC)"
7572

7673

7774

7875
# Verify bridge builds
7976
verify-bridge:
8077
@echo "$(BLUE)Verifying builds...$(NC)"
81-
@for lib in $(OUTPUT_DIR)/*.a; do \
82-
echo "Checking $$(basename $$lib):"; \
83-
file "$$lib"; \
84-
nm "$$lib" | grep -E "(tsc_build_|tsc_validate_|tsc_free_)" | head -5 || true; \
78+
@if [ -d $(OUTPUT_DIR)/TSCBridge.xcframework ]; then \
79+
echo "Checking TSCBridge.xcframework:"; \
80+
find $(OUTPUT_DIR)/TSCBridge.xcframework -name "*.a" -exec file {} \; || true; \
8581
echo ""; \
86-
done
82+
fi
8783

8884
# Setup development environment
8985
setup:
@@ -116,6 +112,8 @@ clean-bridge:
116112
@echo "$(YELLOW)Cleaning C bridge artifacts...$(NC)"
117113
@rm -rf $(OUTPUT_DIR)
118114
@cd $(BRIDGE_DIR) && rm -f *.a *.h
115+
@cd $(BRIDGE_DIR) && rm -rf TSCBridge.xcframework headers
116+
119117

120118
# Development helpers
121119
dev-setup: setup build-bridge-macos

Package.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@ let package = Package(
1515
name: "TSCBridge",
1616
path: "Sources/TSCBridge"
1717
),
18+
.binaryTarget(
19+
name: "TSCBridgeLib",
20+
path: "Sources/TSCBridge/TSCBridge.xcframework"
21+
),
1822
.target(
1923
name: "SwiftTSGo",
2024
dependencies: [
21-
.target(name: "TSCBridge")
22-
],
23-
linkerSettings: [
24-
.unsafeFlags(["-LSources/TSCBridge"]),
25-
.linkedLibrary("tsc_macos", .when(platforms: [.macOS])),
26-
.linkedLibrary("tsc_ios_arm64", .when(platforms: [.iOS])),
25+
.target(name: "TSCBridge"),
26+
.target(name: "TSCBridgeLib"),
2727
]
2828
),
2929
.testTarget(
3030
name: "SwiftTSGoTests",
3131
dependencies: [
32-
.target(name: "SwiftTSGo"),
33-
.target(name: "TSCBridge"),
32+
.target(name: "SwiftTSGo")
3433
],
3534
resources: [
3635
.copy("Resources")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>BinaryPath</key>
9+
<string>libtsc_universal.a</string>
10+
<key>HeadersPath</key>
11+
<string>Headers</string>
12+
<key>LibraryIdentifier</key>
13+
<string>macos-arm64_x86_64</string>
14+
<key>LibraryPath</key>
15+
<string>libtsc_universal.a</string>
16+
<key>SupportedArchitectures</key>
17+
<array>
18+
<string>arm64</string>
19+
<string>x86_64</string>
20+
</array>
21+
<key>SupportedPlatform</key>
22+
<string>macos</string>
23+
</dict>
24+
</array>
25+
<key>CFBundlePackageType</key>
26+
<string>XFWK</string>
27+
<key>XCFrameworkFormatVersion</key>
28+
<string>1.0</string>
29+
</dict>
30+
</plist>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/* Code generated by cmd/cgo; DO NOT EDIT. */
2+
3+
/* package github.com/microsoft/typescript-go/cbridge */
4+
5+
6+
#line 1 "cgo-builtin-export-prolog"
7+
8+
#include <stddef.h>
9+
10+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
11+
#define GO_CGO_EXPORT_PROLOGUE_H
12+
13+
#ifndef GO_CGO_GOSTRING_TYPEDEF
14+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15+
#endif
16+
17+
#endif
18+
19+
/* Start of preamble from import "C" comments. */
20+
21+
22+
#line 3 "c_bridge.go"
23+
24+
#include <stdlib.h>
25+
#include <string.h>
26+
27+
typedef struct {
28+
int code;
29+
char* category;
30+
char* message;
31+
char* file;
32+
int line;
33+
int column;
34+
int length;
35+
} c_diagnostic;
36+
37+
typedef struct {
38+
int success;
39+
char* config_file;
40+
c_diagnostic* diagnostics;
41+
int diagnostic_count;
42+
char** emitted_files;
43+
int emitted_file_count;
44+
char** written_file_paths;
45+
char** written_file_contents;
46+
int written_file_count;
47+
} c_build_result;
48+
49+
typedef struct {
50+
char* path;
51+
char* content;
52+
} c_file_entry;
53+
54+
typedef struct {
55+
c_file_entry* files;
56+
int file_count;
57+
char** directories;
58+
int directory_count;
59+
} c_file_resolver_data;
60+
61+
#line 1 "cgo-generated-wrapper"
62+
63+
64+
/* End of preamble from import "C" comments. */
65+
66+
67+
/* Start of boilerplate cgo prologue. */
68+
#line 1 "cgo-gcc-export-header-prolog"
69+
70+
#ifndef GO_CGO_PROLOGUE_H
71+
#define GO_CGO_PROLOGUE_H
72+
73+
typedef signed char GoInt8;
74+
typedef unsigned char GoUint8;
75+
typedef short GoInt16;
76+
typedef unsigned short GoUint16;
77+
typedef int GoInt32;
78+
typedef unsigned int GoUint32;
79+
typedef long long GoInt64;
80+
typedef unsigned long long GoUint64;
81+
typedef GoInt64 GoInt;
82+
typedef GoUint64 GoUint;
83+
typedef size_t GoUintptr;
84+
typedef float GoFloat32;
85+
typedef double GoFloat64;
86+
#ifdef _MSC_VER
87+
#include <complex.h>
88+
typedef _Fcomplex GoComplex64;
89+
typedef _Dcomplex GoComplex128;
90+
#else
91+
typedef float _Complex GoComplex64;
92+
typedef double _Complex GoComplex128;
93+
#endif
94+
95+
/*
96+
static assertion to make sure the file is being used on architecture
97+
at least with matching size of GoInt.
98+
*/
99+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
100+
101+
#ifndef GO_CGO_GOSTRING_TYPEDEF
102+
typedef _GoString_ GoString;
103+
#endif
104+
typedef void *GoMap;
105+
typedef void *GoChan;
106+
typedef struct { void *t; void *v; } GoInterface;
107+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
108+
109+
#endif
110+
111+
/* End of boilerplate cgo prologue. */
112+
113+
#ifdef __cplusplus
114+
extern "C" {
115+
#endif
116+
117+
extern c_build_result* tsc_build_filesystem(char* projectPath, int printErrors, char* configFile);
118+
extern c_build_result* tsc_build_with_resolver(char* projectPath, int printErrors, char* configFile, c_file_resolver_data* resolverData);
119+
extern char* tsc_validate_simple(char* code);
120+
extern void tsc_free_string(char* str);
121+
extern void tsc_free_result(c_build_result* result);
122+
extern c_file_resolver_data* tsc_create_resolver_data();
123+
extern void tsc_add_file_to_resolver(c_file_resolver_data* data, char* path, char* content);
124+
extern void tsc_add_directory_to_resolver(c_file_resolver_data* data, char* path);
125+
extern void tsc_free_resolver_data(c_file_resolver_data* data);
126+
127+
#ifdef __cplusplus
128+
}
129+
#endif
68 MB
Binary file not shown.

bridge/libtsc_macos.a

-68 MB
Binary file not shown.

0 commit comments

Comments
 (0)