objective-cbuck

How to use Facebook BUCK with DTrace files?


So, if you open https://github.com/airbnb/BuckSample And will try to install with cocoaPods https://github.com/ReactiveCocoa/ReactiveObjC

and after you'll add a new BUCK build rule like

apple_third_party_lib(
    name = "ReactiveObjC",
    visibility = ["PUBLIC"],
    srcs = glob([
        "ReactiveObjC/**/*.m",
    ]),
    exported_headers = glob([
        "ReactiveObjC/**/*.h",
    ]),
    frameworks = [
        "$PLATFORM_DIR/Developer/Library/Frameworks/Foundation.framework",
    ],
)

buck build //Pods:ReactiveObjC will fail with error like this

Pods/ReactiveObjC/ReactiveObjC/RACPassthroughSubscriber.m:12:9: fatal error: 'RACSignalProvider.h' file not found

If we go further we'll see that RACSignalProvider.h is not in the Pod sources, but there is RACSignalProvider.d which is DTrace source file.

When we try to compile it with XCode we can see that there is an extra step before compiling actual framwork

CompileDTraceScript /*user folder*/Pods/ReactiveObjC/ReactiveObjC/RACSignalProvider.d (in target 'ReactiveObjC' from project 'Pods')
    cd /*user folder*/Pods
    /usr/sbin/dtrace -h -s /*user folder*/Pods/ReactiveObjC/ReactiveObjC/RACSignalProvider.d -o /*user folder*/Library/Developer/Xcode/DerivedData/Odnoklassniki-gsukbcogkxolydbhlpglswzdhhpg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/ReactiveObjC.build/DerivedSources/RACSignalProvider.h

which is not happening when we run buck build

Is there something missing from config? Or this just not supported by BUCK?


Solution

  • So the answer is, you need to use a genrule() to process your DTrace files It should look like

    genrule(
        name = "ReactiveObjC_DTrace",
        srcs = [
            "ReactiveObjC/ReactiveObjC/RACSignalProvider.d",
            "ReactiveObjC/ReactiveObjC/RACCompoundDisposableProvider.d",
        ],
        bash = 
    """
        mkdir -p $OUT
        /usr/sbin/dtrace -h -s $SRCDIR/ReactiveObjC/ReactiveObjC/RACSignalProvider.d -o $OUT/RACSignalProvider.h
        /usr/sbin/dtrace -h -s $SRCDIR/ReactiveObjC/ReactiveObjC/RACCompoundDisposableProvider.d -o $OUT/RACCompoundDisposableProvider.h
    """,
        out = "ReactiveObjC_DTrace",
        visibility = ["PUBLIC"]
    )
    

    And then modify your ReactiveObjC rule to look like

    apple_third_party_lib(
        name = "ReactiveObjC",
        visibility = ["PUBLIC"],
        srcs = glob([
            "ReactiveObjC/**/*.m",
        ]),
        deps = [ 
            "//Pods:ReactiveObjC_DTrace",
        ],
        exported_headers = glob([
            "ReactiveObjC/**/*.h",
            "$(location :ReactiveObjC_DTrace)/**/*.h"
        ]),
        frameworks = [
            "$PLATFORM_DIR/Developer/Library/Frameworks/Foundation.framework",
        ],
    )