Skip to content

Commit 7efeacc

Browse files
committed
Some more docs
1 parent afb783b commit 7efeacc

8 files changed

Lines changed: 112 additions & 25 deletions

File tree

‎Package.swift‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ if let localPath = Context.environment["SWIFT_JAVA_JNI_CORE_PATH"] {
1111
swiftJavaJNICoreDep = .package(url: "https://github.com/swiftlang/swift-java-jni-core", branch: "main")
1212
}
1313

14-
// Set SWIFTJAVA_DOCC_PLUGIN_INSTALL=1 to install the docc-plugin automatically.
14+
// Set SWIFTJAVA_DOCC_PLUGIN_INSTALL=1 to install the docc-plugin automatically,
15+
// or DOCC_PLUGIN_PATH=<path> to point at a local checkout.
1516
// This is a workaround because swift-subprocess includes the plugin explicitly,
1617
// which breaks tools trying to add `swift package add-dependency` the plugin
1718
// to swift-java because it thinks the plugin was already added, but it is not.
1819
let extraDependencies: [Package.Dependency]
19-
if Context.environment["SWIFTJAVA_DOCC_PLUGIN_INSTALL"] == "1" {
20+
if let localPath = Context.environment["DOCC_PLUGIN_PATH"] {
21+
extraDependencies = [.package(path: localPath)]
22+
} else if Context.environment["SWIFTJAVA_DOCC_PLUGIN_INSTALL"] == "1" {
2023
extraDependencies = [
2124
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.5.0")
2225
]

‎Sources/SwiftJavaConfigurationShared/Configuration.swift‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ public struct Configuration: Codable {
160160
public var singleType: String?
161161

162162
/// If set, JExtract (JNI mode) will write a linker version script to this
163-
/// path, listing all generated JNI ``@_cdecl`` entry-point symbols as
163+
/// path, listing all generated JNI `@_cdecl` entry-point symbols as
164164
/// global exports and hiding everything else with `local: *`. Pass this
165-
/// file to the linker via ``-Xlinker --version-script=<path>`` to enable
165+
/// file to the linker via `-Xlinker --version-script=<path>` to enable
166166
/// precise dead-code elimination of unused Swift code in the final shared
167167
/// library.
168168
public var linkerExportListOutput: String?
@@ -306,14 +306,44 @@ public struct Configuration: Codable {
306306
}
307307

308308
/// The Java classes that should be translated to Swift. The keys are
309-
/// canonical Java class names (e.g., java.util.Vector) and the values are
310-
/// the corresponding Swift names (e.g., JavaVector).
309+
/// canonical Java class names (e.g., java.util.ArrayList) and the values are
310+
/// the corresponding Swift names (e.g., JavaArrayList).
311+
///
312+
/// Example:
313+
/// ```json
314+
/// {
315+
/// "classes": {
316+
/// "java.util.ArrayList": "JavaArrayList",
317+
/// "java.util.HashMap": "JavaHashMap"
318+
/// }
319+
/// }
320+
/// ```
311321
public var classes: [String: String]? = [:]
312322

313-
// Compile for the specified Java SE release.
323+
/// Compile for the specified Java SE release.
324+
///
325+
/// `JavaVersion` is an integer identifying a Java SE release, in the same
326+
/// shape as `javaSourceLevel`. Supported values:
327+
///
328+
/// - `17`
329+
/// - `18`
330+
/// - `21`
331+
/// - `22`
332+
/// - `24`
333+
/// - `25`
314334
public var sourceCompatibility: JavaVersion?
315335

316-
// Generate class files suitable for the specified Java SE release.
336+
/// Generate class files suitable for the specified Java SE release.
337+
///
338+
/// `JavaVersion` is an integer identifying a Java SE release, in the same
339+
/// shape as `javaSourceLevel`. Supported values:
340+
///
341+
/// - `17`
342+
/// - `18`
343+
/// - `21`
344+
/// - `22`
345+
/// - `24`
346+
/// - `25`
317347
public var targetCompatibility: JavaVersion?
318348

319349
/// Filter input Java types by their package prefix if set

‎Sources/SwiftJavaDocumentation/Documentation.docc/Android.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Android
22

3-
## R8/Proguard Rules
3+
Hints and patterns for using swift-java on Android.
4+
5+
## Overview
6+
7+
### R8/Proguard Rules
48

59
Since swift-java uses JNI and reflection APIs, we must tell the R8 optimizer to ignore our wrapped types,
610
otherwise we will run into runtime crashes, because types are stripped from the APK/AAR.
@@ -16,7 +20,7 @@ For example, if your library is named is `org.swift.exampleapp`, then add the fo
1620
-keep interface org.swift.exampleapp.** { *; }
1721
```
1822

19-
## Android Core Library Desugaring
23+
### Android Core Library Desugaring
2024

2125
If you are using [Core Library Desugaring](https://developer.android.com/studio/write/java8-support) in your
2226
Android project, you must enable the `AndroidCoreLibraryDesugaring` trait to ensure that the SwiftJava wrappers

‎Sources/SwiftJavaDocumentation/Documentation.docc/FeaturesOverview.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Orientation guide for choosing the right swift-java tool for your interop task.
44

5+
## Overview
6+
7+
swift-java has two directions of interop, each with a preferred entry point.
8+
Start here to figure out which tool matches your task, then follow the links
9+
to the per-tool documentation.
10+
511
### Which mode should I use?
612

713
#### Calling Swift from Java

‎Sources/SwiftJavaDocumentation/Documentation.docc/ReducingBinarySize.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
When using the `jextract` tool to wrap your Swift APIs as a Java library, several compiler and linker options can substantially reduce the final binary size by stripping dead code that would otherwise be retained.
44

5+
## Overview
6+
7+
The compiler and linker options below trim the shipped library by stripping
8+
Swift symbols that JNI never calls, then dead-stripping the resulting
9+
unreachable code. Applied together, they can significantly reduce the final
10+
`.so`/`.dylib` size compared to a default release build.
11+
512
### Requirements
613

714
Full binary-size optimization requires **Swift 6.3 or later**. Swift 6.3 introduced the `@used` attribute, which `JExtractSwiftPlugin` attaches to every generated JNI entry point so the compiler cannot eliminate them before the linker has a chance to see them.

‎Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaConfigFile.md‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
SwiftJava tools can be configured using the `swift-java.config` file.
44

5+
## Overview
6+
7+
The `swift-java.config` file lives alongside each target that needs
8+
swift-java code generation. It selects tool modes, sets output paths,
9+
and controls per-mode filters. Below: the file layout, then the full
10+
list of supported keys.
11+
512
### The swift-java.config file
613

714
You can refer to the `SwiftJavaConfigurationShared/Configuration` struct to learn about the supported options.
@@ -13,7 +20,7 @@ please refer to the options documentation for details on their behavior.
1320

1421
The configuration is a JSON 5 file, which among other things allows `//` and `/* */` comments, so feel free to add line comments explaining rationale for some of the settings in your configuration.
1522

16-
## Supported configuration options
23+
### Supported configuration options
1724

1825
<!-- DO NOT EDIT TEXT INSIDE THE SWIFT_JAVA_CONFIG_DOCS BLOCK -->
1926
<!-- Use the ./scripts/generate-config-docs.py to re-generate -->
@@ -231,9 +238,9 @@ If set, only generate bindings for this single Swift type name
231238
- **Type:** `String?`
232239

233240
If set, JExtract (JNI mode) will write a linker version script to this
234-
path, listing all generated JNI ``@_cdecl`` entry-point symbols as
241+
path, listing all generated JNI `@_cdecl` entry-point symbols as
235242
global exports and hiding everything else with `local: *`. Pass this
236-
file to the linker via ``-Xlinker --version-script=<path>`` to enable
243+
file to the linker via `-Xlinker --version-script=<path>` to enable
237244
precise dead-code elimination of unused Swift code in the final shared
238245
library.
239246

@@ -413,8 +420,18 @@ The Java class path that should be passed along to the swift-java tool.
413420
- **Default:** empty dictionary (`[:]`)
414421

415422
The Java classes that should be translated to Swift. The keys are
416-
canonical Java class names (e.g., java.util.Vector) and the values are
417-
the corresponding Swift names (e.g., JavaVector).
423+
canonical Java class names (e.g., java.util.ArrayList) and the values are
424+
the corresponding Swift names (e.g., JavaArrayList).
425+
426+
Example:
427+
```json
428+
{
429+
"classes": {
430+
"java.util.ArrayList": "JavaArrayList",
431+
"java.util.HashMap": "JavaHashMap"
432+
}
433+
}
434+
```
418435

419436
---
420437

@@ -424,6 +441,16 @@ the corresponding Swift names (e.g., JavaVector).
424441

425442
Compile for the specified Java SE release.
426443

444+
`JavaVersion` is an integer identifying a Java SE release, in the same
445+
shape as `javaSourceLevel`. Supported values:
446+
447+
- `17`
448+
- `18`
449+
- `21`
450+
- `22`
451+
- `24`
452+
- `25`
453+
427454
---
428455

429456
#### targetCompatibility
@@ -432,6 +459,16 @@ Compile for the specified Java SE release.
432459

433460
Generate class files suitable for the specified Java SE release.
434461

462+
`JavaVersion` is an integer identifying a Java SE release, in the same
463+
shape as `javaSourceLevel`. Supported values:
464+
465+
- `17`
466+
- `18`
467+
- `21`
468+
- `22`
469+
- `24`
470+
- `25`
471+
435472
---
436473

437474
#### javaFilterInclude

‎Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaJextract.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Automatic Java wrappers for existing Swift code, generated by `swift-java jextra
77

88
`jextract` is the *Java source-generation* part of swift-java.
99

10-
## Workflow
10+
### Workflow
1111

1212
TODO: document all this

‎Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaWrapJava.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ directly — see <doc:FeaturesJavaKitMacros>.
1717

1818
For the full feature matrix, see <doc:FeaturesOverview>.
1919

20-
## Workflow
20+
### Workflow
2121

2222
The typical pipeline has three steps, though the SwiftPM plugin can drive all
2323
of them for you.
@@ -62,7 +62,7 @@ swift-java wrap-java \
6262
Sources/JavaSieve/swift-java.config
6363
```
6464

65-
## The SwiftPM plugin
65+
### The SwiftPM plugin
6666

6767
Most projects do **not** invoke the CLI directly. The `SwiftJavaPlugin`
6868
build-tool plugin (see `Plugins/SwiftJavaPlugin/SwiftJavaPlugin.swift`)
@@ -83,7 +83,7 @@ Wire it up in your `Package.swift`:
8383

8484
See <doc:SwiftPMPlugin> for the plugin's full contract.
8585

86-
## `swift-java.config` schema (wrap-java fields)
86+
### `swift-java.config` schema (wrap-java fields)
8787

8888
The full schema lives in
8989
`Sources/SwiftJavaConfigurationShared/Configuration.swift`. The fields
@@ -101,7 +101,7 @@ that matter for `wrap-java` are:
101101

102102
The config file is JSON5, so `//` and `/* */` comments are permitted.
103103

104-
## CLI flags
104+
### CLI flags
105105

106106
`swift-java wrap-java --help` (from
107107
`Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift`) exposes:
@@ -120,7 +120,7 @@ The config file is JSON5, so `//` and `/* */` comments are permitted.
120120
| `-o <path>` / `--output-directory <path>` | (Inherited) Output directory. |
121121
| `-l <level>` / `--log-level <level>` | (Inherited) `trace`, `debug`, `info`, `notice`, `warning`, `error`, `critical`. |
122122

123-
## Walkthrough: wrapping a JDK class
123+
### Walkthrough: wrapping a JDK class
124124

125125
The simplest possible sample: wrap `java.math.BigInteger` and use it to test
126126
primality. See `Samples/JavaProbablyPrime/`.
@@ -134,7 +134,7 @@ primality. See `Samples/JavaProbablyPrime/`.
134134
}
135135
}
136136

137-
## Walkthrough: wrapping an external JAR
137+
### Walkthrough: wrapping an external JAR
138138

139139
`Samples/JavaSieve/` wraps a third-party Java library (a quadratic-sieve
140140
prime finder) plus `java.math.RoundingMode` for enum-constant access. The
@@ -149,7 +149,7 @@ config lists both the classpath and the target classes.
149149
}
150150
}
151151

152-
## Walkthrough: Maven dependency
152+
### Walkthrough: Maven dependency
153153

154154
`Samples/JavaDependencySampleApp/` wraps `org.apache.commons:commons-csv`
155155
straight from Maven Central. The config here can be near-empty because
@@ -164,7 +164,7 @@ straight from Maven Central. The config here can be near-empty because
164164
}
165165
}
166166

167-
## Feature matrix
167+
### Feature matrix
168168

169169
Legend: ✅ supported, ❌ not supported, 🟡 partial / work-in-progress.
170170

@@ -187,7 +187,7 @@ Legend: ✅ supported, ❌ not supported, 🟡 partial / work-in-progress.
187187
| JAR-only workflow (`swift-java configure --jar` -> `wrap-java`) | ✅ |
188188
| SwiftPM plugin auto-invocation | ✅ |
189189

190-
## See also
190+
### See also
191191

192192
- <doc:FeaturesJavaKitMacros> — the underlying macro surface that `wrap-java` generates.
193193
- <doc:SwiftJavaCommandLineTool> — full reference for the `swift-java` CLI (all subcommands).

0 commit comments

Comments
 (0)