Skip to content

Commit

Permalink
fix: provide SWIFTPM_MODULE_BUNDLE macro for Objective-C targets wi…
Browse files Browse the repository at this point in the history
…th resources (#781)

- Generate `SWIFTPM_MODULE_BUNDLE` macro [inspired by the one provided
by
SPM](https://github.com/apple/swift-package-manager/blob/8387798811c6cc43761c5e1b48df2d3412dc5de4/Sources/Build/BuildDescription/ClangTargetBuildDescription.swift#L390).
- Ensure that the macro is available to all of the ObjC code by adding
the `-include` flag to the `copts` with the location of the resource
accessor header file.
- Update the `resources_example` to use a vendored version of
[AppLovin-MAX-Swift-Package](https://github.com/AppLovin/AppLovin-MAX-Swift-Package).
This package has an ObjC target with resources that expects the
`SWIFTPM_MODULE_BUNDLE` macro to be present.

Closes #372.
Closes #774.
  • Loading branch information
cgrindel authored Dec 8, 2023
1 parent 109a69f commit f7330bb
Show file tree
Hide file tree
Showing 61 changed files with 1,492 additions and 23 deletions.
1 change: 1 addition & 0 deletions examples/resources_example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ swift_deps.from_file(
use_repo(
swift_deps,
"swiftpkg_another_package_with_resources",
"swiftpkg_app_lovin_sdk",
"swiftpkg_googlesignin_ios",
"swiftpkg_package_with_resources",
)
Expand Down
3 changes: 2 additions & 1 deletion examples/resources_example/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import PackageDescription
let package = Package(
name: "resources_example",
dependencies: [
.package(path: "third_party/package_with_resources"),
.package(path: "third_party/another_package_with_resources"),
.package(path: "third_party/app_lovin_sdk"),
.package(path: "third_party/package_with_resources"),
.package(url: "https://github.com/google/GoogleSignIn-iOS", from: "7.0.0"),
]
)
5 changes: 4 additions & 1 deletion examples/resources_example/Tests/MyAppTests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ swift_library(
],
module_name = "MyAppTests",
tags = ["manual"],
deps = ["@swiftpkg_package_with_resources//:Sources_CoolUI"],
deps = [
"@swiftpkg_app_lovin_sdk//:Sources_AppLovinSDKResources",
"@swiftpkg_package_with_resources//:Sources_CoolUI",
],
)

ios_unit_test(
Expand Down
6 changes: 6 additions & 0 deletions examples/resources_example/Tests/MyAppTests/MyAppTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AppLovinSDKResources
import CoolUI
import SwiftUI
import XCTest
Expand All @@ -7,4 +8,9 @@ class MyAppTests: XCTestCase {
let actual = CoolStuff.title()
XCTAssertNotNil(actual)
}

func test_AppLovinSDKResources() throws {
let url = ALResourceManager.resourceBundleURL
XCTAssertNotNil(url)
}
}
36 changes: 36 additions & 0 deletions examples/resources_example/swift_deps_index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"direct_dep_identities": [
"another_package_with_resources",
"app_lovin_sdk",
"googlesignin-ios",
"package_with_resources"
],
Expand All @@ -15,6 +16,26 @@
"MoreCoolUI"
]
},
{
"name": "AppLovinSDKResources",
"c99name": "AppLovinSDKResources",
"src_type": "objc",
"label": "@swiftpkg_app_lovin_sdk//:Sources_AppLovinSDKResources",
"package_identity": "app_lovin_sdk",
"product_memberships": [
"AppLovinSDK"
]
},
{
"name": "AppLovinSDK",
"c99name": "AppLovinSDK",
"src_type": "binary",
"label": "@swiftpkg_app_lovin_sdk//:remote_archive_AppLovinSDK-12.0.0.xcframework.zip_AppLovinSDK",
"package_identity": "app_lovin_sdk",
"product_memberships": [
"AppLovinSDK"
]
},
{
"name": "AppAuth",
"c99name": "AppAuth",
Expand Down Expand Up @@ -132,6 +153,14 @@
"@swiftpkg_another_package_with_resources//:MoreCoolUI"
]
},
{
"identity": "app_lovin_sdk",
"name": "AppLovinSDK",
"type": "library",
"target_labels": [
"@swiftpkg_app_lovin_sdk//:Sources_AppLovinSDKResources"
]
},
{
"identity": "appauth-ios",
"name": "AppAuth",
Expand Down Expand Up @@ -230,6 +259,13 @@
"path": "third_party/another_package_with_resources"
}
},
{
"name": "swiftpkg_app_lovin_sdk",
"identity": "app_lovin_sdk",
"local": {
"path": "third_party/app_lovin_sdk"
}
},
{
"name": "swiftpkg_appauth_ios",
"identity": "appauth-ios",
Expand Down
56 changes: 56 additions & 0 deletions examples/resources_example/third_party/app_lovin_sdk/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "AppLovinSDK",
defaultLocalization: "en",
products: [
.library(
name: "AppLovinSDK",
targets: ["AppLovinSDKResources"]
),
],
dependencies: [],
targets: [
// This is a wrapper target to configure various settings and resources required by main binary target.
.target(
name: "AppLovinSDKResources",
dependencies: [
.target(name: "AppLovinSDK")
],
resources: [
.process("AppLovinSDKResources.bundle")
],
linkerSettings: [
.linkedFramework("AdSupport"),
.linkedFramework("AppTrackingTransparency"),
.linkedFramework("AudioToolbox"),
.linkedFramework("AVFoundation"),
.linkedFramework("CoreGraphics"),
.linkedFramework("CoreMedia"),
.linkedFramework("CoreMotion"),
.linkedFramework("CoreTelephony"),
.linkedFramework("Foundation"),
.linkedFramework("MessageUI"),
.linkedFramework("SafariServices"),
.linkedFramework("StoreKit"),
.linkedFramework("SystemConfiguration"),
.linkedFramework("UIKit"),
.linkedFramework("WebKit"),

.linkedLibrary("z"),

// NOTE: Swift Package Manager currently does not allow dependencies with unsafeFlags, unless a specific branch/commit is used.
// For now, these flags should be added manually to the project for integration.
// .unsafeFlags(["-ObjC"])
]
),
.binaryTarget(
name: "AppLovinSDK",
url: "https://artifacts.applovin.com/ios/com/applovin/applovin-sdk/AppLovinSDK-12.0.0.xcframework.zip",
checksum: "4dd0cc968a7b90b98024661f8b2c3f2ffe6c25af63369e53f84980321c902b3d"
)
]
)
30 changes: 30 additions & 0 deletions examples/resources_example/third_party/app_lovin_sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
NOTE: This is a vendored verision of https://github.com/AppLovin/AppLovin-MAX-Swift-Package.
Unfortunatley, the code in the repository had [a bug in an
init](https://github.com/AppLovin/AppLovin-MAX-Swift-Package/blob/ef3d2fd34380552067c834afad3c8b732e62569b/Sources/AppLovinSDKResources/ALResourceManager.m#L22)
that prevented us from depending upon it directly. This vendored code has applied a fix.

===

# AppLovin MAX iOS SDK

AppLovin MAX iOS SDK for Swift Package Manager.

## Installation

The [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate the AppLovin MAX SDK into your Xcode project using Swift Package Manager:

1. Add it to the `dependencies` of your `Package.swift`:

```swift
dependencies: [
.package(url: "https://github.com/AppLovin/AppLovin-MAX-Swift-Package.git", .upToNextMajor(from: "10.3.6"))
]
```

2. Enable the `-ObjC` flag in Xcode: click on your project settings, go to **Build Settings**, search for **Other Linker Flags** and add `-ObjC`.

Check out our integration [docs](https://dash.applovin.com/documentation/mediation/ios/getting-started/integration) for more info on getting started with the AppLovin MAX SDK.

Note, this Swift package only includes the main AppLovin MAX SDK. We currently do not support installing MAX mediation network adapters using Swift Package Manager.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// AppLovinSDK.h
// AppLovinSDK
//
// Created by Ritam Sarmah on 7/2/21.
// Copyright © 2021 AppLovin Corporation. All rights reserved.
//

#import <AppLovinSDK/AppLovinSDK.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ALResourceManager.m
// AppLovinSDK
//
// Created by Ritam Sarmah on 11/3/21.
// Copyright © 2021 AppLovin Corporation. All rights reserved.
//

#import "ALResourceManager.h"

@implementation ALResourceManager

static NSURL *ALResourceBundleURL;

+ (void)initialize
{
[super initialize];

ALResourceBundleURL = [SWIFTPM_MODULE_BUNDLE URLForResource: @"AppLovinSDKResources" withExtension: @"bundle"];
}

+ (NSURL *)resourceBundleURL
{
return ALResourceBundleURL;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"states": [{
"id": 14,
"is_initial_state": true,
"type": "att",
"destination_state_id": 99
}, {
"id": 99,
"type": "reinit"
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"states": [{
"id": 1,
"is_initial_state": true,
"type": "alert",
"title": {
"key": "PP_TITLE",
"key_unified_flow": "PP_TITLE_UNIFIED_FLOW",
"replacements": ["<APP_NAME>"]
},
"message": {
"key": "AGREE_MESSAGE",
"key_unified_flow": "AGREE_MESSAGE_UNIFIED_FLOW"
},
"transitions": [{
"title": {
"key": "AGREE_TO_TERMS_BUTTON_TITLE",
"key_unified_flow": "CONTINUE_BUTTON_TITLE_UNIFIED_FLOW"
},
"style": "default",
"destination_state_id": 12
}]
}, {
"id": 12,
"type": "event",
"name": "tos_ok",
"destination_state_id": 99
}, {
"id": 99,
"type": "reinit"
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"states": [{
"id": 1,
"is_initial_state": true,
"type": "alert",
"title": {
"key": "PP_TITLE",
"key_unified_flow": "PP_TITLE_UNIFIED_FLOW",
"replacements": ["<APP_NAME>"]
},
"message": {
"key": "AGREE_MESSAGE",
"key_unified_flow": "AGREE_MESSAGE_UNIFIED_FLOW"
},
"transitions": [{
"title": {
"key": "AGREE_TO_TERMS_BUTTON_TITLE",
"key_unified_flow": "CONTINUE_BUTTON_TITLE_UNIFIED_FLOW"
},
"style": "default",
"destination_state_id": 12
}]
}, {
"id": 12,
"type": "event",
"name": "tos_ok",
"destination_state_id": 14
}, {
"id": 14,
"type": "att",
"destination_state_id": 99
}, {
"id": 99,
"type": "reinit"
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"states": [{
"id": 1,
"is_initial_state": true,
"type": "alert",
"title": {
"key": "PP_AND_TOS_TITLE",
"key_unified_flow": "PP_AND_TOS_TITLE_UNIFIED_FLOW",
"replacements": ["<APP_NAME>"]
},
"message": {
"key": "AGREE_MESSAGE",
"key_unified_flow": "AGREE_MESSAGE_UNIFIED_FLOW"
},
"transitions": [{
"title": {
"key": "AGREE_TO_TERMS_BUTTON_TITLE",
"key_unified_flow": "CONTINUE_BUTTON_TITLE_UNIFIED_FLOW"
},
"style": "default",
"destination_state_id": 12
}]
}, {
"id": 12,
"type": "event",
"name": "tos_ok",
"destination_state_id": 99
}, {
"id": 99,
"type": "reinit"
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"states": [{
"id": 1,
"is_initial_state": true,
"type": "alert",
"title": {
"key": "PP_AND_TOS_TITLE",
"key_unified_flow": "PP_AND_TOS_TITLE_UNIFIED_FLOW",
"replacements": ["<APP_NAME>"]
},
"message": {
"key": "AGREE_MESSAGE",
"key_unified_flow": "AGREE_MESSAGE_UNIFIED_FLOW"
},
"transitions": [{
"title": {
"key": "AGREE_TO_TERMS_BUTTON_TITLE",
"key_unified_flow": "CONTINUE_BUTTON_TITLE_UNIFIED_FLOW"
},
"style": "default",
"destination_state_id": 12
}]
}, {
"id": 12,
"type": "event",
"name": "tos_ok",
"destination_state_id": 14
}, {
"id": 14,
"type": "att",
"destination_state_id": 99
}, {
"id": 99,
"type": "reinit"
}]
}
Loading

0 comments on commit f7330bb

Please sign in to comment.