我想尝试一下bazel,然后用它包装zlib。项目布局很简单,这是文件ROJECTROOT/3rd_party/zlib/BUILD
:
cc_library(
name = "zlib",
srcs = [
"adler32.c",
"compress.c",
"crc32.c",
"crc32.h",
"deflate.c",
"deflate.h",
"gzclose.c",
"gzguts.h",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inffast.h",
"inffixed.h",
"inflate.c",
"inflate.h",
"inftrees.c",
"inftrees.h",
"trees.c",
"trees.h",
"uncompr.c",
"zconf.h",
"zutil.c",
"zutil.h",
],
hdrs = ["zlib.h"],
)
然后我在 VS 2017开发人员命令提示符中运行bazel :
bazel build //3rd_party/zlib:zlib --verbose_failures
它突然声称:
ERROR: D:/projects/bazeltesting/3rd_party/zlib/BUILD:1:1: C++ compilation of rule '//3rd_party/zlib:zlib' failed (Exit 2): cl.exe failed: error executing command
cd C:/users/yangxi/_bazel_yangxi/y7qzzhw6/execroot/__main__
SET INCLUDE=
SET PATH=;C:\WINDOWS\system32
SET PWD=/proc/self/cwd
SET TEMP=C:\Users\yangxi\AppData\Local\Temp
SET TMP=C:\Users\yangxi\AppData\Local\Temp
C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/genfiles /Ibazel-out/x64_windows-fastbuild/bin /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Fobazel-out/x64_windows-fastbuild/bin/3rd_party/zlib/_objs/zlib/inftrees.obj /c 3rd_party/zlib/inftrees.c
Execution platform: @bazel_tools//platforms:host_platform
c:\users\yangxi\_bazel_yangxi\y7qzzhw6\execroot\__main__\3rd_party\zlib\zconf.h(247): fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
Target //3rd_party/zlib:zlib failed to build
奇怪的是,有时它声称stdio.h
,有时是stddef.h
,都是随机的。
此外,该项目可以使用普通包装的CMake进行编译,可以生成为VS2017项目并在没有其他选项的情况下进行编译:
include_guard(GLOBAL)
cmake_minimum_required(VERSION 3.0)
project(zlib)
file(GLOB zlib_source_files *.c)
add_library(zlib_static STATIC ${zlib_source_files})
target_include_directories(zlib_static PUBLIC ${zlib_SOURCE_DIR})
set_target_properties(zlib_static PROPERTIES FOLDER "3rd_party")
if(NOT MSVC)
target_compile_options(zlib_static PUBLIC -fPIC)
endif()
那么如何与bazel和msvc一起使用?