Skip to content

Add SPM support: vendored leveldb 1.22.5, wrapper kept verbatim MRC via -fno-objc-arc#2

Open
damian-kolasinski wants to merge 1 commit into
masterfrom
spm-support
Open

Add SPM support: vendored leveldb 1.22.5, wrapper kept verbatim MRC via -fno-objc-arc#2
damian-kolasinski wants to merge 1 commit into
masterfrom
spm-support

Conversation

@damian-kolasinski

@damian-kolasinski damian-kolasinski commented Jul 18, 2026

Copy link
Copy Markdown

Adds Swift Package Manager support so consumers (KingsChat iOS) can drop both the Objective-LevelDB and leveldb-library CocoaPods — while keeping the wrapper sources verbatim MRC, byte-identical to master apart from exactly one bug fix.

What's inside

Package.swift

  • swift-tools-version 5.9, platform iOS 15, cxxLanguageStandard: .gnucxx14.
  • Product Objective-LevelDB built from target Objective_LevelDB. The target/module name deliberately matches the module name CocoaPods generated for this pod, so existing imports keep working unchanged:
    • #import <Objective_LevelDB/LevelDB.h>
    • #import <Objective_LevelDB/Objective-LevelDB-umbrella.h> (a matching umbrella header is shipped in the public headers)
  • The wrapper stays MRC: ARC is disabled via cSettings: [.unsafeFlags(["-fno-objc-arc"])] — the same pattern as appunite/protobuf, proven to work through Tuist with revision pinning. Because of the unsafe flag, this package can only be consumed by revision/branch, not by semver version.
  • Internal target LevelDBLibrary: the vendored leveldb C++ library. It is intentionally NOT named leveldb to avoid an SPM target-name collision with firebase/leveldb when both packages end up in the same dependency graph (e.g. alongside firebase-ios-sdk).

Vendored leveldb (vendor/leveldb)

  • Sources copied from https://github.com/firebase/leveldb tag CocoaPods-1.22.5 (commit a0bc79961d7be727d258d33d5a6b2f1023270ba1) — the exact tree the leveldb-library CocoaPods pod (resolved as 1.22.5 by consumers today) is built from; upstream leveldb 1.22 plus Firebase's build patches.
  • Excluded: all tests/benchmarks, db/leveldbutil.cc, Windows-specific files (env_windows*, windows_logger.h), db/c_test.c.
  • Same build settings as the pod: LEVELDB_PLATFORM_POSIX, LEVELDB_IS_BIG_ENDIAN=0, HAVE_FULLFSYNC=1, links libc++, ships the pod's PrivacyInfo.xcprivacy.

The single wrapper change (vs master)

Classes/LevelDB.mm, initWithPath:name:andOptions:: _name = name; and _path = path; stored the ivars without retaining them (direct ivar assignment bypasses the retain property setters), leaving _name/_path dangling once the caller's strings are released. Fixed MRC-style; the complete wrapper diff vs master:

--- a/Classes/LevelDB.mm
+++ b/Classes/LevelDB.mm
@@ -117,8 +117,8 @@
 - (id) initWithPath:(NSString *)path name:(NSString *)name andOptions:(LevelDBOptions)opts {
     self = [super init];
     if (self) {
-        _name = name;
-        _path = path;
+        _name = [name retain];
+        _path = [path retain];
         
         leveldb::Options options;
@@ -664,6 +664,8 @@
 - (void) dealloc {
     [self close];
+    [_name release];
+    [_path release];
     [super dealloc];
 }

(master's dealloc never released either ivar, so the releases are added alongside.)

Everything else — all other wrapper sources, headers, and the podspec (requires_arc = false, version 2.1.4) — is byte-identical to master; git diff master -- Classes Objective-LevelDB.podspec shows only the two hunks above plus the new Classes/include/ shim headers.

Validation

  • xcodebuild -scheme Objective-LevelDB -destination "generic/platform=iOS Simulator" build — succeeds (also generic/platform=iOS).
  • A scratch ObjC consumer package depending on this package builds clean (fresh DerivedData, simulator + device) using the exact import spellings above and exercises databaseInLibraryWithName:, encoder/decoder blocks, setObject:forKey:, key/object prefix enumeration and NSStringFromLevelDBKey.
  • Verified -fno-objc-arc lands after Xcode's default -fobjc-arc on the wrapper compile commands (last flag wins); MRC constructs like [super dealloc] would be hard compile errors under ARC, so the successful build is itself proof ARC is off.

https://claude.ai/code/session_01LTj6vGgu7NmTs7bjupWAGh

@damian-kolasinski damian-kolasinski changed the title Add Swift Package Manager support with vendored leveldb 1.22.5 Add SPM support: vendored leveldb 1.22.5, wrapper kept verbatim MRC via -fno-objc-arc Jul 18, 2026
- Add Package.swift (swift-tools-version 5.9, iOS 15) exposing the
  Objective-LevelDB library product built from the Objective_LevelDB
  target (module name matches what CocoaPods generated, so existing
  #import <Objective_LevelDB/...> spellings keep working).
- Vendor Google's leveldb under vendor/leveldb from
  https://github.com/firebase/leveldb tag CocoaPods-1.22.5 (the exact
  source tree the leveldb-library CocoaPods pod is built from),
  excluding tests, benchmarks and Windows-specific files. Built as the
  LevelDBLibrary target with the same defines as the pod
  (LEVELDB_PLATFORM_POSIX, LEVELDB_IS_BIG_ENDIAN=0, HAVE_FULLFSYNC=1).
- Keep the wrapper sources verbatim MRC: ARC is disabled for the
  Objective_LevelDB target via cSettings unsafeFlags -fno-objc-arc
  (same pattern as appunite/protobuf), which means the package must be
  consumed by revision/branch, not by version. Podspec is untouched.
- One bug fix: initWithPath:name:andOptions: stored the name and path
  ivars without retaining them (direct ivar assignment bypasses the
  retain property setters), leaving _name/_path dangling once the
  caller's strings are released. Now retained on init and released in
  dealloc.
- Add Classes/include/Objective_LevelDB forwarding public headers,
  including an Objective-LevelDB-umbrella.h that mirrors the
  CocoaPods-generated umbrella header.

Claude-Session: https://claude.ai/code/session_01LTj6vGgu7NmTs7bjupWAGh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant