Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@asciimike
Last active July 11, 2022 13:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asciimike/1f0799e38d1e96a993319da4645fa0b4 to your computer and use it in GitHub Desktop.
Save asciimike/1f0799e38d1e96a993319da4645fa0b4 to your computer and use it in GitHub Desktop.
Example of how to reference a CocoaPod in Bazel
ios_app(
name = "App",
hdrs = ["src/*.h"],
srcs = ["src/*.m"],
deps = [
"@SDWebImage//:latest_library",
],
)
ios_test(
name = "Test",
hdrs = ["test/*.h"],
srcs = ["test/*.m"],
deps = [
"@SDWebImage//:latest_library",
],
xctest = 1,
)
objc_xcodeproj(
name = "Project",
deps = [
":App",
":Tests",
],
)
# bazel build :Project builds the app and unit tests
# Based on https://github.com/rs/SDWebImage/blob/master/SDWebImage.podspec
new_git_repository(
name = "SDWebImage",
remote = "https://github.com/rs/SDWebImage.git",
build_file_content = """
objc_library(
name = "latest_library",
hdrs = glob(
["SDWebImage/{NS,SD,UI}*.h"],
exclude = ["SDWebImage/UIImage+WebP.h"],
),
srcs = glob(
["SDWebImage/{NS,SD,UI}*.m"],
exclude = ["SDWebImage/UIImage+WebP.m"],
),
sdk_frameworks = "ImageIO",
visibility = ["//visibility:public"],
)""",
)
{
"name": "SDWebImage",
"version": "3.7.1",
"platforms": {
"ios": "5.0"
},
"license": "MIT",
"summary": "Asynchronous image downloader with cache support with an UIImageView category.",
"homepage": "https://github.com/rs/SDWebImage",
"authors": {
"Olivier Poitrey": "rs@dailymotion.com"
},
"source": {
"git": "https://github.com/rs/SDWebImage.git",
"tag": "3.7.1"
},
"description": "This library provides a category for UIImageView with support for remote images coming from the web. It provides an UIImageView category adding web image and cache management to the Cocoa Touch framework, an asynchronous image downloader, an asynchronous memory + disk image caching with automatic cache expiration handling, a guarantee that the same URL won't be downloaded several times, a guarantee that bogus URLs won't be retried again and again, and performances!",
"requires_arc": true,
"frameworks": "ImageIO",
"default_subspecs": "Core",
"subspecs": [
{
"name": "Core",
"source_files": "SDWebImage/{NS,SD,UI}*.{h,m}",
"exclude_files": "SDWebImage/UIImage+WebP.{h,m}"
},
{
"name": "MapKit",
"source_files": "SDWebImage/MKAnnotationView+WebCache.*",
"frameworks": "MapKit",
"dependencies": {
"SDWebImage/Core": [
]
}
},
{
"name": "WebP",
"source_files": "SDWebImage/UIImage+WebP.{h,m}",
"xcconfig": {
"GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SD_WEBP=1"
},
"dependencies": {
"SDWebImage/Core": [
],
"libwebp": [
]
}
}
]
}
@luwang2728
Copy link

What is sdwebimage.podspec.json for and how to use it in bazel?

@norpol
Copy link

norpol commented Jun 20, 2018

No clue either.
Thread for reference: bazelbuild/bazel#1813 (comment)

@keith
Copy link

keith commented Sep 17, 2019

I think it was just a comparison between the podspec and the BUILD file for reference of how you may convert them

@asciimike
Copy link
Author

Correct, this doesn't (to my knowledge) actually exist, it's purely a "I wish the world worked like this."

@keith
Copy link

keith commented Sep 20, 2019

Ah FWIW this works:

objc_library(
    name = "SDWebImage",
    srcs = glob(
        ["SDWebImage/*.m"],
        exclude = [
            "SDWebImage/UIImage+WebP.m",
            "SDWebImage/SDWebImageWebPCoder.m",
        ],
    ),
    hdrs = glob(
        ["SDWebImage/*.h"],
        exclude = [
            "SDWebImage/UIImage+WebP.h",
            "SDWebImage/SDWebImageWebPCoder.h",
        ],
    ),
    module_name = "SDWebImage",
    sdk_frameworks = [
        "ImageIO",
        "MobileCoreServices",
    ],
    visibility = ["//visibility:public"],
)

@asciimike
Copy link
Author

asciimike commented Sep 20, 2019

Sure, provided you download the SDWebImage source, yeah? I was hoping to jam that into Bazel so it could do some of the package management as well (even though that's not really what it's meant for).

EDIT: I guess if you do the git repo thing you can avoid that?

@keith
Copy link

keith commented Sep 20, 2019

Yea we use this file with http_archive but git_repository would work just as well

@rockwotj
Copy link

For anyone who stumbles upon this again (hi Mike 👋) here's an updated BUILD file for the latest SDWebImage library

objc_library(
    name = "SDWebImage",
    srcs = glob(
        [
            "SDWebImage/Core/*.m",
            "SDWebImage/Private/*.m",
            "SDWebImage/Private/*.h",
        ],
        exclude = [],
    ),
    hdrs = glob(
        [
            "SDWebImage/Core/*.h",
        ],
        exclude = [],
    ),
    module_name = "SDWebImage",
    sdk_frameworks = [
        "ImageIO",
    ],
    includes = [
        "SDWebImage/Core",
        "SDWebImage/Private",
    ],
    visibility = ["//visibility:public"],
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment