Skip to content

Commit 695f025

Browse files
committed
working with snapshot toolchains also on arm
1 parent 2e42b28 commit 695f025

File tree

5 files changed

+61
-65
lines changed

5 files changed

+61
-65
lines changed

Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ BUILD_DIR := .build/$(ARCH_SUBDIR)-apple-macosx
3737
LIB_SUFFIX := dylib
3838
endif
3939

40+
ifeq ($(UNAME), Darwin)
41+
ifeq ("${TOOLCHAINS}", "")
42+
SWIFTC := "xcrun swiftc"
43+
else
44+
SWIFTC := "xcrun ${TOOLCHAINS}/usr/bin/swiftc"
45+
endif
46+
else
47+
ifeq ("${TOOLCHAINS}", "")
48+
SWIFTC := "swiftc"
49+
else
50+
SWIFTC := "${TOOLCHAINS}/usr/bin/swiftc"
51+
endif
52+
endif
53+
4054
SAMPLES_DIR := "Samples"
4155

4256
all: generate-all
@@ -83,13 +97,13 @@ JEXTRACT_BUILD_DIR="$(BUILD_DIR)/jextract"
8397
define make_swiftinterface
8498
$(eval $@_MODULE = $(1))
8599
$(eval $@_FILENAME = $(2))
86-
eval swiftc \
100+
eval ${SWIFTC} \
87101
-emit-module-interface-path ${JEXTRACT_BUILD_DIR}/${$@_MODULE}/${$@_FILENAME}.swiftinterface \
88102
-emit-module-path ${JEXTRACT_BUILD_DIR}/${$@_MODULE}/${$@_FILENAME}.swiftmodule \
89103
-enable-library-evolution \
90-
-Xfrontend -abi-comments-in-module-interface \
104+
-Xfrontend -abi-comments-in-module-interface \
91105
-module-name ${$@_MODULE} \
92-
-Xfrontend -abi-comments-in-module-interface \
106+
-Xfrontend -abi-comments-in-module-interface \
93107
Sources/${$@_MODULE}/${$@_FILENAME}.swift
94108
echo "Generated: ${JEXTRACT_BUILD_DIR}/${$@_MODULE}/${$@_FILENAME}.swiftinterface"
95109
endef

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ The primary purpose of this repository is to create an environment for collabora
1616

1717
## Dependencies
1818

19+
### Required Swift Development Toolchains
20+
21+
To build and use this project, currently, you will need to download a custom toolchain which includes some improvements in Swift that this project relies on:
22+
23+
**Required toolchain download:**
24+
25+
- Go to https://www.swift.org/download/
26+
- Find the "latest" `Trunk Development (main)` toolchain for your OS
27+
28+
If these are too old, you can resort to one of these fallback toolchains:
29+
30+
Fallback development toolchain on **macOS**:
31+
32+
- https://ci.swift.org/job/swift-PR-toolchain-macos/1539/artifact/branch-main/swift-PR-76905-1539-osx.tar.gz
33+
34+
Fallback development toolchain on **Linux (Ubuntu 22.04)**:
35+
36+
```
37+
URL=$(curl -s "https://ci.swift.org/job/oss-swift-package-ubuntu-22_04/lastSuccessfulBuild/consoleText" | grep 'Toolchain: ' | sed 's/Toolchain: //g')
38+
wget ${URL}
39+
```
40+
41+
or just use the provided docker image (explained below).
42+
43+
https://www.swift.org/download/
44+
45+
46+
### Required JDK versions
47+
1948
This project consists of different modules which have different Swift and Java runtime requirements.
2049

2150
**JavaKit** – the Swift macros allowing the invocation of Java libraries from Swift

Sources/JExtractSwift/Swift2JavaTranslator.swift

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -105,60 +105,8 @@ extension Swift2JavaTranslator {
105105
translator: self
106106
)
107107
visitor.walk(sourceFileSyntax)
108-
109-
try await self.postProcessImportedDecls()
110108
}
111109

112-
public func postProcessImportedDecls() async throws {
113-
log.debug(
114-
"Post process imported decls...",
115-
metadata: [
116-
"types": "\(importedTypes.count)",
117-
"global/funcs": "\(importedGlobalFuncs.count)",
118-
]
119-
)
120-
121-
// FIXME: the use of dylibs to get symbols is a hack we need to remove and replace with interfaces containing mangled names
122-
let dylibPath = ".build/arm64-apple-macosx/debug/lib\(swiftModuleName).dylib"
123-
guard var dylib = SwiftDylib(path: dylibPath) else {
124-
log.warning(
125-
"""
126-
Unable to find mangled names for imported symbols. Dylib not found: \(dylibPath) This method of obtaining symbols is a workaround; it will be removed.
127-
"""
128-
)
129-
return
130-
}
131-
132-
importedGlobalFuncs = try await importedGlobalFuncs._mapAsync { funcDecl in
133-
let funcDecl = try await dylib.fillInMethodMangledName(funcDecl)
134-
log.info("Mapped method '\(funcDecl.identifier)' -> '\(funcDecl.swiftMangledName)'")
135-
return funcDecl
136-
}
137-
138-
importedTypes = Dictionary(uniqueKeysWithValues: try await importedTypes._mapAsync { (tyName, tyDecl) in
139-
var tyDecl = tyDecl
140-
log.info("Mapping type: \(tyDecl.swiftTypeName)")
141-
142-
tyDecl = try await dylib.fillInTypeMangledName(tyDecl)
143-
144-
log.info("Mapping members of: \(tyDecl.swiftTypeName)")
145-
tyDecl.initializers = try await tyDecl.initializers._mapAsync { initDecl in
146-
dylib.log.logLevel = .info
147-
148-
let initDecl = try await dylib.fillInAllocatingInitMangledName(initDecl)
149-
log.info("Mapped initializer '\(initDecl.identifier)' -> '\(initDecl.swiftMangledName)'")
150-
return initDecl
151-
}
152-
153-
tyDecl.methods = try await tyDecl.methods._mapAsync { funcDecl in
154-
let funcDecl = try await dylib.fillInMethodMangledName(funcDecl)
155-
log.info("Mapped method '\(funcDecl.identifier)' -> '\(funcDecl.swiftMangledName)'")
156-
return funcDecl
157-
}
158-
159-
return (tyName, tyDecl)
160-
})
161-
}
162110
}
163111

164112
// ===== --------------------------------------------------------------------------------------------------------------

Tests/JExtractSwiftTests/FunctionDescriptorImportTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ extension FunctionDescriptorTests {
141141
javaPackage: String = "com.example.swift",
142142
swiftModuleName: String = "SwiftModule",
143143
logLevel: Logger.Level = .trace,
144-
body: (String) async throws -> ()
145-
) async throws {
144+
body: (String) throws -> ()
145+
) throws {
146146
let st = Swift2JavaTranslator(
147147
javaPackage: javaPackage,
148148
swiftModuleName: swiftModuleName
149149
)
150150
st.log.logLevel = logLevel
151151

152-
try await st.analyze(swiftInterfacePath: "/fake/Sample.swiftinterface", text: interfaceFile)
152+
try st.analyze(swiftInterfacePath: "/fake/Sample.swiftinterface", text: interfaceFile)
153153

154154
let funcDecl = st.importedGlobalFuncs.first {
155155
$0.baseIdentifier == methodIdentifier
@@ -159,7 +159,7 @@ extension FunctionDescriptorTests {
159159
st.printFunctionDescriptorValue(&printer, funcDecl)
160160
}
161161

162-
try await body(output)
162+
try body(output)
163163
}
164164

165165
func variableAccessorDescriptorTest(
@@ -168,15 +168,15 @@ extension FunctionDescriptorTests {
168168
javaPackage: String = "com.example.swift",
169169
swiftModuleName: String = "SwiftModule",
170170
logLevel: Logger.Level = .trace,
171-
body: (String) async throws -> ()
172-
) async throws {
171+
body: (String) throws -> ()
172+
) throws {
173173
let st = Swift2JavaTranslator(
174174
javaPackage: javaPackage,
175175
swiftModuleName: swiftModuleName
176176
)
177177
st.log.logLevel = logLevel
178178

179-
try await st.analyze(swiftInterfacePath: "/fake/Sample.swiftinterface", text: interfaceFile)
179+
try st.analyze(swiftInterfacePath: "/fake/Sample.swiftinterface", text: interfaceFile)
180180

181181
let varDecl: ImportedVariable? =
182182
st.importedTypes.values.compactMap {
@@ -192,7 +192,7 @@ extension FunctionDescriptorTests {
192192
st.printFunctionDescriptorValue(&printer, varDecl.accessorFunc(kind: accessorKind)!, accessorKind: accessorKind)
193193
}
194194

195-
try await body(getOutput)
195+
try body(getOutput)
196196
}
197197

198198
}

docker/install_untested_nightly_swift.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ set -euo pipefail
1616

1717
echo "Download [nightly] [untested] Swift toolchain for: $(uname -m)"
1818

19-
declare -r SWIFT_UNTESTED_TOOLCHAIN_JOB_URL="https://ci.swift.org/job/oss-swift-package-ubuntu-22_04/lastSuccessfulBuild/consoleText"
19+
ARCH="$(arch)"
20+
if [[ "$ARCH" = "i386" ]]; then
21+
SWIFT_UNTESTED_TOOLCHAIN_JOB_URL="https://ci.swift.org/job/oss-swift-package-ubuntu-22_04/lastSuccessfulBuild/consoleText"
22+
else
23+
SWIFT_UNTESTED_TOOLCHAIN_JOB_URL="https://ci.swift.org/job/oss-swift-package-ubuntu-22_04-aarch64/lastSuccessfulBuild/consoleText"
24+
fi
2025

2126
if [[ "$(grep "22.04" /etc/lsb-release)" = "" ]]; then
22-
echo "This script specifically only supports Ubuntu 20.04 due to nightly toolchain availability"
27+
echo "This script specifically only supports Ubuntu 22.04 due to nightly toolchain availability"
2328
exit 1
2429
fi
2530

0 commit comments

Comments
 (0)