fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
ced94dec
0.10.0
1# This BUILD file was written based off of the `build.rs` script for the Rust 2# crate `libgit2-sys`. For more details, see the crate's source: 3# https://github.com/rust-lang/git2-rs/tree/libgit2-sys-0.13.0/libgit2-sys 4 5load ( "@bazel_skylib//lib:selects.bzl" , "selects" ) 6load ( "@bazel_skylib//rules:common_settings.bzl" , "bool_flag" ) 7load ( "@bazel_skylib//rules:write_file.bzl" , "write_file" ) 8load ( "@rules_cc//cc:defs.bzl" , "cc_library" ) 9 10[ 11config_setting ( 12name = plat , 13constraint_values = [ "@platforms//os:{}" . format ( plat )], 14) 15for plat in [ 16"macos" , 17"ios" , 18"tvos" , 19"windows" , 20] 21] 22 23# env::var("CARGO_FEATURE_SSH").is_ok() 24bool_flag ( 25name = "ssh" , 26build_setting_default = False , 27) 28 29config_setting ( 30name = "ssh_setting" , 31flag_values = { ":ssh" : "True" }, 32) 33 34# target.contains("apple") 35selects . config_setting_group ( 36name = "apple" , 37match_any = [ 38":macos" , 39":ios" , 40":tvos" , 41], 42) 43 44[ 45config_setting ( 46name = "cpu_" + cpu , 47constraint_values = [ "@platforms//cpu:{}" . format ( cpu )], 48) 49for cpu in [ 50"i386" , 51"x86_32" , 52] 53] 54 55# env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32" 56selects . config_setting_group ( 57name = "pointer_width_32" , 58match_any = [ 59"cpu_i386" , 60"cpu_x86_32" , 61], 62) 63 64# env::var("CARGO_FEATURE_HTTPS").is_ok() 65bool_flag ( 66name = "https" , 67build_setting_default = False , 68) 69 70config_setting ( 71name = "https_setting" , 72flag_values = { ":https" : "True" }, 73) 74 75# if https && target.contains("windows") 76selects . config_setting_group ( 77name = "https_windows" , 78match_all = [ 79":https_setting" , 80":windows" , 81], 82) 83 84# if https && target.contains("apple") 85selects . config_setting_group ( 86name = "https_apple" , 87match_all = [ 88":https_setting" , 89":apple" , 90], 91) 92 93cc_library ( 94name = "http-parser" , 95srcs = glob ([ "deps/http-parser/*.c" ]), 96hdrs = glob ([ "deps/http-parser/*.h" ]), 97copts = select ({ 98# Required in `opt` builds to solve the following error 99# libpcre.a(pcre_compile.o): requires unsupported dynamic reloc 11; recompile with -fPIC 100"@platforms//os:linux" : [ "-fPIC" ], 101"//conditions:default" : [], 102}), 103includes = [ "deps/http-parser" ], 104linkstatic = True , 105) 106 107cc_library ( 108name = "pcre" , 109srcs = glob ([ "deps/pcre/**/*.c" ]), 110hdrs = glob ([ "deps/pcre/**/*.h" ]), 111copts = select ({ 112# Required in `opt` builds to solve the following error 113# libhttp-parser.a(http_parser.o): requires unsupported dynamic reloc 11; recompile with -fPIC 114"@platforms//os:linux" : [ "-fPIC" ], 115"//conditions:default" : [], 116}), 117defines = [ 118"HAVE_STDINT_H=1" , 119"HAVE_MEMMOVE=1" , 120"NO_RECURSE=1" , 121"NEWLINE=10" , 122"POSIX_MALLOC_THRESHOLD=10" , 123"LINK_SIZE=2" , 124"PARENS_NEST_LIMIT=250" , 125"MATCH_LIMIT=10000000" , 126"MATCH_LIMIT_RECURSION=MATCH_LIMIT" , 127"MAX_NAME_SIZE=32" , 128"MAX_NAME_COUNT=10000" , 129], 130includes = [ "deps/pcre" ], 131linkstatic = True , 132) 133 134write_file ( 135name = "configure_features" , 136out = "include/git2/sys/features.h" , 137content = [ 138" #ifndef INCLUDE_features_h", 139" #define INCLUDE_features_h", 140" #define GIT_THREADS 1", 141" #define GIT_TRACE 1", 142] + 143# !target.contains("android") 144select ({ 145"@platforms//os:android" : [], 146"//conditions:default" : [ "#define GIT_USE_NSEC 1"], 147}) + select ({ 148":apple" : [ " #define GIT_USE_STAT_MTIMESPEC 1"], 149" // conditions : default ": [" #define GIT_USE_STAT_MTIM 1"], 150}) + select ({ 151":pointer_width_32" : [ " #define GIT_ARCH_32 1"], 152" // conditions : default ": [" #define GIT_ARCH_64 1"], 153}) + [ 154" #define GIT_SHA1_COLLISIONDETECT 1", 155] + select ({ 156":ssh_setting" : [ " #define GIT_SSH 1"], 157" // conditions : default ": [], 158}) + select ({ 159":https_apple" : [ 160" #define GIT_HTTPS 1", 161" #define GIT_SECURE_TRANSPORT 1", 162], 163":https_setting" : [ 164" #define GIT_HTTPS 1", 165" #define GIT_OPENSSL 1", 166], 167# target.contains("windows") 168":https_windows" : [ 169" #define GIT_HTTPS 1", 170" #define GIT_WINHTTP 1", 171], 172"//conditions:default" : [], 173}) + select ({ 174":apple" : [ " #define GIT_USE_ICONV 1"], 175" // conditions : default ": [], 176}) + [ 177" #endif", 178], 179) 180 181cc_library ( 182name = "include" , 183hdrs = [ ":configure_features" ] + glob ([ "include/**/*.h" ]), 184strip_include_prefix = "include" , 185) 186 187cc_library ( 188name = "git2" , 189srcs = [ 190"src/allocators/failalloc.c" , 191"src/allocators/stdalloc.c" , 192"src/allocators/win32_leakcheck.c" , 193# Use the CollisionDetection SHA1 implementation. 194"src/hash/sha1/collisiondetect.c" , 195"src/hash/sha1/sha1dc/sha1.c" , 196"src/hash/sha1/sha1dc/ubc_check.c" , 197] + glob ( 198include = [ 199"src/*.c" , 200"src/xdiff/*.c" , 201"src/transports/*.c" , 202"src/streams/*.c" , 203"src/hash/*.c" , 204], 205exclude = [ 206"src/win32/**" , 207"src/unix/**" , 208], 209) + select ({ 210"@platforms//os:windows" : glob ([ "src/win32/**/*.c" ]), 211"//conditions:default" : glob ([ "src/unix/**/*.c" ]), 212}), 213hdrs = [ 214"src/allocators/failalloc.h" , 215"src/allocators/stdalloc.h" , 216"src/allocators/win32_leakcheck.h" , 217# Use the CollisionDetection SHA1 implementation. 218"src/hash/sha1/collisiondetect.h" , 219"src/hash/sha1/sha1dc/sha1.h" , 220"src/hash/sha1/sha1dc/ubc_check.h" , 221] + glob ( 222include = [ 223"src/*.h" , 224"src/xdiff/*.h" , 225"src/transports/*.h" , 226"src/streams/*.h" , 227"src/hash/*.h" , 228], 229exclude = [ 230"src/win32/**" , 231"src/unix/**" , 232], 233) + select ({ 234"@platforms//os:windows" : glob ([ "src/win32/**/*.h" ]), 235"//conditions:default" : glob ([ "src/unix/**/*.h" ]), 236}), 237copts = select ({ 238"@platforms//os:linux" : [ 239"-fvisibility=hidden" , 240"-fPIC" , 241"-Wall" , 242"-std=gnu90" , 243# On linux, optimization is required to avoid issues with missing (and unused) symbols: 244# `liblibgit2.a(pack.pic.o):pack.c:function packfile_open_locked: error: undefined reference to 'fstat'` 245# 246# Always enabling optimization helps us avoid this though, it does seem unnecessary and this should 247# probably be fixed. 248"-O3" , 249], 250"@platforms//os:windows" : [], 251"//conditions:default" : [ 252"-fvisibility=hidden" , 253"-fPIC" , 254"-Wall" , 255"-std=gnu90" , 256], 257}), 258defines = [ 259# Use the CollisionDetection SHA1 implementation. 260"SHA1DC_NO_STANDARD_INCLUDES=1" , 261"SHA1DC_CUSTOM_INCLUDE_SHA1_C=\\\"common.h\\\ "" , 262"SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\\\"common.h\\\ "" , 263# Use the included PCRE regex backend. 264"GIT_REGEX_BUILTIN=1" , 265] + select ({ 266":windows" : [ "STRSAFE_NO_DEPRECATE" ], 267"//conditions:default" : [], 268}), 269linkstatic = True , 270strip_include_prefix = "src" , 271visibility = [ "//visibility:public" ], 272deps = [ 273":http-parser" , 274":include" , 275":pcre" , 276"@zlib" , 277], 278) 279 280alias ( 281name = "libgit2" , 282actual = ":git2" , 283visibility = [ "//visibility:public" ], 284)