DebugSwift icon indicating copy to clipboard operation
DebugSwift copied to clipboard

Feature: Remove package for production version

Open Ali72 opened this issue 5 months ago • 2 comments

Hi, Thanks for your great work on DebugSwift! The package is really helpful during development, but in many cases, we want to completely remove it from production builds — similar to how other debug tools like FLEX allow full exclusion.

Currently, when using DebugSwift via Swift Package Manager, the package (and all its files) are always compiled and linked, even if we disable it at runtime (e.g., using DebugSwift.disable() in release builds). This causes:

  • Unwanted binary bloat
  • Security/code audit concerns
  • Longer compile times

Suggested Solution: You can simply add a unique prefix like DebugSwift.<rest of name> to all your file names, which makes it easy to exclude them from production builds using the EXCLUDED_SOURCE_FILE_NAMES setting in the build settings.

Thanks again for your work on this! We'd love to see support for this feature to make DebugSwift even more flexible and production-safe.

Ali72 avatar Aug 01 '25 08:08 Ali72

Hey @Ali72, thanks so much for you amazing comment! Can you try this approach first?

🛠️ Step-by-Step: Isolating DebugSwift via a Target-Based Dependency

🧱 Step 1: Create a New “DebugSupport” Target

This new target will contain all debug-only dependencies and logic.

In Xcode:

  1. Go to File > New > Target…
  2. Select Framework > Swift Framework
  3. Name it DebugSupport
  4. Make sure it’s added to the Debug build configuration only (more on that in Step 5)

🔗 Step 2: Add DebugSwift to DebugSupport Only

If using Swift Package Manager:

  1. Open Project Settings > Package Dependencies

  2. Add DebugSwift if you haven’t already

  3. In the Framework & Library section of the DebugSupport target:

    • Add DebugSwift.framework (under "Link Binary with Libraries")

🧠 You're now isolating the debug dependency to a separate module.


📦 Step 3: Re-export DebugSwift from DebugSupport (Optional)

In DebugSupport.swift inside the new target:

@_exported import DebugSwift

✅ This makes DebugSwift APIs directly accessible to other modules that import DebugSupport.


🧪 Step 4: Use DebugSupport in Your App Target (Debug Only)

In your main app target, conditionally import and use:

#if DEBUG
import DebugSupport

func setupDebugTools() {
    DebugSwift.enable()
}
#endif

This ensures all usage is scoped to debug builds only.


⚙️ Step 5: Limit DebugSupport to Debug Builds Only

In Build Settings for your app target:

  • Go to Build Phases > Link Binary With Libraries

  • Add DebugSupport.framework only for the Debug configuration:

    • Click the + icon and add DebugSupport.framework
    • Then click the dropdown > Do Not Embed / Debug only

Optional:

  • You can also use Xcode Schemes:

    • Duplicate your main scheme as “Release”
    • In Edit Scheme > Build > Targets, uncheck DebugSupport from the “Release” scheme

🧹 Step 6: Clean Up Imports in Your App

You should now:

  • Remove direct imports of DebugSwift from your app code
  • Only import DebugSupport (guarded by #if DEBUG)
  • This will fully isolate the debug tooling to debug builds and prevent any runtime references from leaking into release builds

✅ Benefits of This Approach

  • 💡 Keeps production binary lean (no dead code, no linked debug tools)
  • 🔒 Reduces risk of exposing debug APIs in production
  • 🔁 Reusable pattern for other debug tools like FLEX, Reveal, etc.

maatheusgois-dd avatar Aug 02 '25 01:08 maatheusgois-dd

If works, can you open a PR adding a md in a folder docs and add the ref in the readme? how use only in debug 😅

maatheusgois-dd avatar Aug 02 '25 01:08 maatheusgois-dd