bazel-xcode / PodToBUILD

An easy way to integrate CocoaPods into Bazel
Apache License 2.0
322 stars 69 forks source link

Headers are not found by objc_library on Bazel 4.0.0 #171

Closed dgcoffman closed 3 years ago

dgcoffman commented 3 years ago

Running

bazel build Example --verbose_failures --spawn_strategy=sandboxed --incompatible_run_shell_command_string=false --incompatible_objc_provider_remove_compile_info=false

Note --incompatible_objc_provider_remove_compile_info=false due to https://github.com/pinterest/PodToBUILD/issues/170

WORKSPACE

    ### PodToBUILD
    http_archive(
        name = "rules_pods",
        urls = ["https://github.com/pinterest/PodToBUILD/releases/download/3.4.1-ea20598f/PodToBUILD.zip"],
    )

    ### Apple
    http_archive(
        name = "build_bazel_rules_apple",
        sha256 = "a41a75c291c69676b9974458ceee09aea60cee0e1ee282e27cdc90b679dfd30f",
        url = "https://github.com/bazelbuild/rules_apple/releases/download/0.21.2/rules_apple.0.21.2.tar.gz",
    )

    http_archive(
        name = "build_bazel_apple_support",
        sha256 = "02ac04ff0a0de1e891a1fa8839cc6a5957e3c4a80856545aa35a786d15aad108",
        url = "https://github.com/bazelbuild/apple_support/releases/download/0.9.1/apple_support.0.9.1.tar.gz",
    )

    http_archive(
        name = "build_bazel_rules_swift",
        sha256 = "d0e5f888b2ccce42c92e6d4686b5507b4230462627f965f9d39862e11ae9fb35",
        url = "https://github.com/bazelbuild/rules_swift/releases/download/0.18.0/rules_swift.0.18.0.tar.gz",
    )

BUILD.bazel

objc_library(
    name = "Example",
    srcs = [
        "ios/Example/main.m",
    ],
    hdrs = glob(["ios/Example/*.h"]),
    deps = [
        "//Vendor/Folly",
    ],
)

Pods.WORKSPACE

new_pod_repository(
    name = "Folly",
    generate_header_map = True,
    podspec_url = "node_modules/react-native/third-party-podspecs/Folly.podspec",
    url = "https://github.com/facebook/folly/archive/v2020.01.13.00.zip",
)

I get result

Vendor/Folly/folly/net/NetOps.cpp:17:10: fatal error: 'folly/net/NetOps.h' file not found
#include <folly/net/NetOps.h>

or

Vendor/Folly/folly/container/detail/F14Table.cpp:17:10: fatal error: 'folly/container/detail/F14Table.h' file not found
#include <folly/container/detail/F14Table.h>

or any number of other errors due to some header file not being found.

Screen Shot 2021-02-19 at 1 09 37 PM

Not just Folly, but all pods that would require header mapping now seem to fail in this way.

Using the Folly podspec shipping with React Native:

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

Pod::Spec.new do |spec|
  spec.name = 'Folly'
  spec.version = '2020.01.13.00'
  spec.license = { :type => 'Apache License, Version 2.0' }
  spec.homepage = 'https://github.com/facebook/folly'
  spec.summary = 'An open-source C++ library developed and used at Facebook.'
  spec.authors = 'Facebook'
  spec.source = { :git => 'https://github.com/facebook/folly.git',
                  :tag => "v#{spec.version}" }
  spec.module_name = 'folly'
  spec.dependency 'boost-for-react-native'
  spec.dependency 'DoubleConversion'
  spec.dependency 'glog'
  spec.compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_HAVE_PTHREAD=1 -Wno-comma -Wno-shorten-64-to-32 -Wno-documentation'
  spec.source_files = 'folly/String.cpp',
                      'folly/Conv.cpp',
                      'folly/Demangle.cpp',
                      'folly/FileUtil.cpp',
                      'folly/Format.cpp',
                      'folly/lang/SafeAssert.cpp',
                      'folly/ScopeGuard.cpp',
                      'folly/Unicode.cpp',
                      'folly/dynamic.cpp',
                      'folly/json.cpp',
                      'folly/json_pointer.cpp',
                      'folly/container/detail/F14Table.cpp',
                      'folly/detail/Demangle.cpp',
                      'folly/detail/UniqueInstance.cpp',
                      'folly/hash/SpookyHashV2.cpp',
                      'folly/lang/Assume.cpp',
                      'folly/lang/CString.cpp',
                      'folly/memory/detail/MallocImpl.cpp',
                      'folly/net/NetOps.cpp',
                      'folly/portability/SysUio.cpp'

  # workaround for https://github.com/facebook/react-native/issues/14326
  spec.preserve_paths = 'folly/*.h',
                        'folly/container/*.h',
                        'folly/container/detail/*.h',
                        'folly/detail/*.h',
                        'folly/functional/*.h',
                        'folly/hash/*.h',
                        'folly/lang/*.h',
                        'folly/memory/*.h',
                        'folly/memory/detail/*.h',
                        'folly/net/*.h',
                        'folly/net/detail/*.h',
                        'folly/portability/*.h'
  spec.libraries           = "stdc++"
  spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
                               "CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
                               "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\"" }

  spec.default_subspec = 'Default'

  spec.subspec 'Default' do
    # no-op
  end

  spec.subspec 'Fabric' do |fabric|
    fabric.source_files = 'folly/SharedMutex.cpp',
                          'folly/concurrency/CacheLocality.cpp',
                          'folly/detail/Futex.cpp',
                          'folly/synchronization/ParkingLot.cpp',
                          'folly/portability/Malloc.cpp'
    fabric.preserve_paths = 'folly/concurrency/CacheLocality.h',
                            'folly/synchronization/ParkingLot.h',
                            'folly/synchronization/SanitizeThread.h',
                            'folly/system/ThreadId.h'
  end

  # Pinning to the same version as React.podspec.
  spec.platforms = { :ios => "10.0", :tvos => "10.0" }
end

I've also tried https://raw.githubusercontent.com/facebook/react-native/master/third-party-podspecs/RCT-Folly.podspec -- no change.

@jerrymarino I read your comment on https://github.com/bazelbuild/bazel/issues/12131#issuecomment-696446794, saying that PodToBUILD should take care of this. Maybe it's broken in Bazel 4.0.0?

I wonder if any of the breaking changes affect this? https://github.com/bazelbuild/bazel/issues?q=label%3Abreaking-change-4.0+is%3Aclosed

Just downgraded and it does seem to find Folly's headers on Bazel 3.7.2 without generate_header_maps:

# This works on Bazel 3.7.2
new_pod_repository(
    name = "Folly",
    install_script = """
        __INIT_REPO__
        # __has_include erroneously returns true for damangle.h, which later causes an link error
        sed -i '' 's/__has_include(<demangle.h>)/false/g' folly/detail/Demangle.h
        rm -rf pod_support/Headers/Public/*
    """,
    podspec_url = "third_party/podspecs/Folly.podspec",
    url = "https://github.com/facebook/folly/archive/v2020.01.13.00.zip",
)
capezzbr commented 3 years ago

I am facing the same issue, can anybody help out with this please?

jparise commented 3 years ago

Resolved by #174