Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library not loaded: @rpath/libswiftFoundation.dylib when using Xcode 11.2.1, but works fine with Xcode 10.3 #684

Closed
jverkoey opened this issue Dec 27, 2019 · 9 comments · Fixed by google/xctestrunner#13

Comments

@jverkoey
Copy link
Contributor

jverkoey commented Dec 27, 2019

Context

I am trying to add bazel 1.0 support to https://github.com/material-foundation/material-testing-ios. The support was added in the bazel1 branch, which was reviewed in material-foundation/material-testing-ios#6.

Notably, this library includes a ios_unit_test_suite target that depends on both an objc_library and a swift_library. When the swift_library dependency is removed, the tests pass on all Xcode versions.

Repro steps

Clone the repo and the branch:

git clone https://github.com/material-foundation/material-testing-ios.git
cd material-testing-ios

Then try to test with Xcode 11.2.1:

bazel test //... --apple_platform_type=ios --ios_minimum_os=10.0 --xcode_version=11.2.1

This fails, with the following output:

INFO: Analyzed 14 targets (0 packages loaded, 0 targets configured).
INFO: Found 10 targets and 4 test targets...
FAIL: //:UnitTests_IPAD_PRO_12_9_IN_9_3 (see /private/var/tmp/_bazel_featherless/3b6682438fd07dd4083ef63da58b9a2a/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/UnitTests_IPAD_PRO_12_9_IN_9_3/test.log)
FAIL: //:UnitTests_IPHONE_7_PLUS_IN_10_3 (see /private/var/tmp/_bazel_featherless/3b6682438fd07dd4083ef63da58b9a2a/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/UnitTests_IPHONE_7_PLUS_IN_10_3/test.log)
FAIL: //:UnitTests_IPHONE_X_IN_11_4 (see /private/var/tmp/_bazel_featherless/3b6682438fd07dd4083ef63da58b9a2a/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/UnitTests_IPHONE_X_IN_11_4/test.log)
INFO: Elapsed time: 1.760s, Critical Path: 1.66s
INFO: 6 processes: 6 darwin-sandbox.
INFO: Build completed, 3 tests FAILED, 4 total actions
//:UnitTests_IPHONE_XS_MAX_IN_12_2                              (cached) PASSED in 2.9s
//:UnitTests_IPAD_PRO_12_9_IN_9_3                                        FAILED in 1.4s
  /private/var/tmp/_bazel_featherless/3b6682438fd07dd4083ef63da58b9a2a/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/UnitTests_IPAD_PRO_12_9_IN_9_3/test.log
//:UnitTests_IPHONE_7_PLUS_IN_10_3                                       FAILED in 1.5s
  /private/var/tmp/_bazel_featherless/3b6682438fd07dd4083ef63da58b9a2a/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/UnitTests_IPHONE_7_PLUS_IN_10_3/test.log
//:UnitTests_IPHONE_X_IN_11_4                                            FAILED in 1.6s
  /private/var/tmp/_bazel_featherless/3b6682438fd07dd4083ef63da58b9a2a/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/UnitTests_IPHONE_X_IN_11_4/test.log

INFO: Build completed, 3 tests FAILED, 4 total actions

Output of one of the log files:

ts_IPAD_PRO_12_9_IN_9_3/test.log
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:UnitTests_IPAD_PRO_12_9_IN_9_3
-----------------------------------------------------------------------------
2019-12-27 20:44:22,364 Will consider the test as test type logic_test to run.
2019-12-27 20:44:22,855 Failed to import biplist module. Will use tool /usr/libexec/PlistBuddy to handle the binary format plist.
2019-12-27 20:44:22,859 Failed to import biplist module. Will use tool /usr/libexec/PlistBuddy to handle the binary format plist.
2019-12-27 20:44:22,864 Failed to import biplist module. Will use tool /usr/libexec/PlistBuddy to handle the binary format plist.
2019-12-27 20:44:22,868 Failed to import biplist module. Will use tool /usr/libexec/PlistBuddy to handle the binary format plist.
2019-12-27 20:44:22,873 Failed to import biplist module. Will use tool /usr/libexec/PlistBuddy to handle the binary format plist.
2019-12-27 20:44:22,883 Failed to import biplist module. Will use tool /usr/libexec/PlistBuddy to handle the binary format plist.
2019-12-27 20:44:22,898 Creating a new simulator:
Name: New-iPad Pro (12.9-inch)-9.3
OS: iOS 9.3
Type: iPad Pro (12.9-inch)
2019-12-27 20:44:23,207 Created new simulator F8F7123E-53E2-494F-9703-B75AC67516D3.
2019-12-27 15:44:23.667 xctest[89456:2623465] The bundle “UnitTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2019-12-27 15:44:23.669 xctest[89456:2623465] (dlopen_preflight(/var/folders/nf/gl8gqkdd6fg98rjd9rgzkt70002gv0/T/test_runner_work_dir.z9xQSa/UnitTests/UnitTests.xctest/UnitTests): Library not loaded: @rpath/libswiftFoundation.dylib
  Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib/libXCTestSwiftSupport.dylib
  Reason: image not found)
2019-12-27 20:44:23,678 Deleting simulator F8F7123E-53E2-494F-9703-B75AC67516D3 asynchronously.
2019-12-27 20:44:23,682 Done.

Then try to build with Xcode 10.3:

bazel test //... --apple_platform_type=ios --ios_minimum_os=10.0 --xcode_version=10.3

This succeeds, with the following output:

INFO: Build option --xcode_version has changed, discarding analysis cache.
INFO: Analyzed 14 targets (0 packages loaded, 1086 targets configured).
INFO: Found 10 targets and 4 test targets...
INFO: Elapsed time: 84.997s, Critical Path: 32.05s
INFO: 231 processes: 224 darwin-sandbox, 3 local, 4 worker.
INFO: Build completed successfully, 230 total actions
//:UnitTests_IPAD_PRO_12_9_IN_9_3                                        PASSED in 2.2s
//:UnitTests_IPHONE_7_PLUS_IN_10_3                                       PASSED in 2.5s
//:UnitTests_IPHONE_XS_MAX_IN_12_2                                       PASSED in 2.7s
//:UnitTests_IPHONE_X_IN_11_4                                            PASSED in 2.7s

INFO: Build completed successfully, 230 total actions

Environment

> bazel version
Build label: 2.0.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 19 12:33:30 2019 (1576758810)
Build timestamp: 1576758810
Build timestamp as int: 1576758810
@jverkoey
Copy link
Contributor Author

Snapshot of the BUILD file for reference:

load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test_suite")
load("@bazel_ios_warnings//:strict_warnings_objc_library.bzl", "strict_warnings_objc_library")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load("@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl", "ios_test_runner")

licenses(["notice"])  # Apache 2.0

exports_files(["LICENSE"])

strict_warnings_objc_library(
    name = "MDFTesting",
    srcs = glob([
        "src/*.m",
    ]),
    hdrs = glob([
        "src/*.h",
    ]),
    enable_modules = 1,
    includes = ["src"],
    sdk_frameworks = ["XCTest"],
    visibility = ["//visibility:public"],
)

swift_library(
    name = "MDFTestingSwift",
    srcs = glob([
        "src/*.swift",
    ]),
    module_name = "MDFTesting",
    visibility = ["//visibility:public"],
)

objc_library(
    name = "UnitTestsLib",
    srcs = glob([
        "examples/MDFTestingExample/MDFTestingExampleTests/*.m",
    ]),
    deps = [
        ":MDFTesting",
    ],
    testonly = 1,
)

swift_library(
    name = "SwiftUnitTestsLib",
    srcs = glob([
        "examples/MDFTestingExample/MDFTestingExampleTests/*.swift",
    ]),
    deps = [
        ":MDFTestingSwift",
    ],
    testonly = 1,
)

ios_test_runner(
    name = "IPAD_PRO_12_9_IN_9_3",
    device_type = "iPad Pro (12.9-inch)",
    os_version = "9.3",
)

ios_test_runner(
    name = "IPHONE_7_PLUS_IN_10_3",
    device_type = "iPhone 7 Plus",
    os_version = "10.3",
)

ios_test_runner(
    name = "IPHONE_X_IN_11_4",
    device_type = "iPhone X",
    os_version = "11.4",
)

ios_test_runner(
    name = "IPHONE_XS_MAX_IN_12_2",
    device_type = "iPhone Xs Max",
    os_version = "12.2",
)

ios_unit_test_suite(
    name = "UnitTests",
    deps = [
      ":UnitTestsLib",
      ":SwiftUnitTestsLib",
    ],
    minimum_os_version = "9.0",
    timeout = "short",
    runners = [
        ":IPAD_PRO_12_9_IN_9_3",
        ":IPHONE_7_PLUS_IN_10_3",
        ":IPHONE_X_IN_11_4",
        ":IPHONE_XS_MAX_IN_12_2",
    ],
)

And the WORKSPACE:


load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", "http_archive")

git_repository(
    name = "build_bazel_rules_apple",
    remote = "https://github.com/bazelbuild/rules_apple.git",
    commit = "19f031f09185e0fcd722c22e596d09bd6fff7944",  # 0.19.0
    shallow_since = "1570721035 -0700",  # 10-10-2019
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_apple_support//lib:repositories.bzl",
    "apple_support_dependencies",
)

apple_support_dependencies()

git_repository(
    name = "bazel_ios_warnings",
    remote = "https://github.com/material-foundation/bazel_ios_warnings.git",
    commit = "c3f720c0838af1ee53299aa6efda87cf729146b4",  # v3.0.0
    shallow_since = "1545400728 -0500"  # 12-21-2018
)

# This override of the zlib package resolves the following error:
# "no such package '@zlib//': The repository '@zlib' could not be resolved"
# Additional context available at: https://github.com/bazelbuild/bazel/issues/10270
http_archive(
    name = "zlib",
    build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
    sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
    strip_prefix = "zlib-1.2.11",
    urls = [
        "https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
        "https://zlib.net/zlib-1.2.11.tar.gz",
    ],
)

jverkoey pushed a commit to material-foundation/material-testing-ios that referenced this issue Dec 27, 2019
Note that due to bazelbuild/rules_apple#684 this has only been confirmed to work with Xcode 10.3.

Example invocation:

```
bazel test //... --apple_platform_type=ios --ios_minimum_os=10.0 --xcode_version=10.3
```
@thomasvl
Copy link
Member

Use a more recent commit, there were some changes needed for the swift library support. Per the quick setup, the repos aren't tagging directly any more, so you'll need to select a hash to use.

@thomasvl
Copy link
Member

Actually, what host os version are you on also, the swift runtime libraries got real complicated in those Xcode versions (as to when to bundle and where to bundle), so it could be some combination of things there also.

@jverkoey
Copy link
Contributor Author

macOS: 10.14.6 (18G2022)

Xcode Version 11.2.1 (11B500)
Xcode Version 10.3 (10G8)

Will try using a later sha next week.

@jverkoey
Copy link
Contributor Author

I found b/142265780, which appears to be related to this issue.

Connecting #495 to this thread, which may also be a relevant discussion to start up again.

cl/280014348 appears to have fixed the issue internally, so I will send a patch to the public runner with the fix.

@jverkoey
Copy link
Contributor Author

Drafting up google/xctestrunner#13 for review.

@jverkoey
Copy link
Contributor Author

jverkoey commented Jan 2, 2020

google/xctestrunner#13 turned out to be a particularly nuanced issue. I've updated its description to capture the nuance.

@thomasvl
Copy link
Member

thomasvl commented Jan 7, 2020

Where does this end up, is the issue entirely in the runner?

@jverkoey
Copy link
Contributor Author

jverkoey commented Jan 7, 2020

It was, yep, but the runner dependency will need to be updated once a release is cut in order to resolve this issue.

@keith keith closed this as completed Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants