rules_apple icon indicating copy to clipboard operation
rules_apple copied to clipboard

Inherting a class from dynamic framework(`ios_framework`) throws undefined symbol errors

Open sanju-naik opened this issue 1 year ago • 1 comments

What's the issue?

We have a dynamic framework that has open class and we have a static library that inherits the open class from Framework and depends on the underlying swift_library. It looks something like this

Foo Framework

open class Foo {
    public var name: String? 
    public init() { }

    public convenience init(name: String) {
        self.init()
        self.name = name
    }

    private func someFunction() {
        print("Hello world")
    }
}

Bar Library

import Foo

public final class Bar: Foo {
    public convenience init(name: String) {
        self.init(name: name)
    }
}

When I run Bazel build for release configuration --compilation_mode=opt , it throws undefied symbol error for the private function from dynamic framework private func someFunction()

How to reproduce

To reproduce this clone - https://github.com/sanju-naik/Bazel-Example.git and check out the dynamic-framework-issues branch.

Running the following command should throw error - bazel build --config=Release --ios_multi_cpus=sim_arm64 BazelDemo

Error Message

  (cd /private/var/tmp/_bazel_sanju/e107e611dd65132537122ef1dabd8e89/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneSimulator \
    APPLE_SDK_VERSION_OVERRIDE=16.4 \
    PATH=/Users/sanju/Library/Caches/bazelisk/downloads/bazelbuild/bazel-6.3.2-darwin-arm64/bin:/opt/homebrew/opt/openjdk/bin:/Users/sanju/.rbenv/shims:/Users/sanju/.rbenv/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin \
    XCODE_VERSION_OVERRIDE=14.3.0.14E222b \
    ZERO_AR_DATE=1 \
  external/local_config_cc/wrapped_clang @bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-acb08275552e/bin/BazelDemo_bin-2.params)
# Configuration: b94fcb8744f284f7d0ecde69e1d097360d802dc23000b86c0429a22d42c495f9
# Execution platform: @local_config_platform//:host
Undefined symbols for architecture arm64:
  "_$s3FooAAC12someFunction33_EDFAF2F1CEBC6FC422A5A3D516B36930LLyyF", referenced from:
      _$s3BarAACN in libBar.a(Bar.swift.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
Target //:BazelDemo failed to build
INFO: Elapsed time: 0.359s, Critical Path: 0.22s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

Note:

Build works fine in Debug mode i.e --compilation_mode=dbg , throws error only in case of Release mode, seems like when optimisations are turned on its dropping the private function?

sanju-naik avatar Sep 26 '23 15:09 sanju-naik

Bumping this, Can someone please take a look at this? 🙏

Note - issue happens only when we add dependency as a dynamic framework & that too only when using compilation mode opt.

sanju-naik avatar Sep 29 '23 00:09 sanju-naik

The example linked uses rules_ios along with some flags that could effect things here. If this is still an issue and reproing open an issue in rules_ios

luispadron avatar Feb 27 '24 06:02 luispadron