我正在尝试使用Conan进行包管理,使用Bazel作为我的C ++代码的构建工具。我使用柯南的原因是因为JFrog Artifactory支持它,我将其用作我的Artifactory Repository。
为此,我提出了以下计划:
$/home/mytimer=> ls -lrt
0 Sep 25 11:57 WORKSPACE
4096 Sep 25 12:00 build / 4096 Sep 25 12:02 main /
$/home/mytimer=> ls -l main
total 4
60 Sep 25 12:02 BUILD
61 Sep 25 11:56 conanfile.txt
955 Sep 25 11:56 timer.cpp
$/home/mytimer=> ls -l build
total 8
1266 Sep 25 12:00 conanbuildinfo.gcc
1875 Sep 25 12:00 conaninfo.txt
(这是我执行conan后 - 安装../main)
$/home/mytimer=> cat cat main/conanfile.txt
[requires]
Poco/1.7.8p3@pocoproject/stable
[generators]
gcc
$/home/mytimer=>cat build/conanbuildinfo.gcc
-DPOCO_STATIC=ON -DPOCO_NO_AUTOMATIC_LIBS -I"/home/.conan/data/Poco/1.7.8p3/pocoproject/stable/package/da23483d46b7229cbae8615ce1ea2594635f3a5f/include" -I"/home/.conan/data/OpenSSL/1.0.2l/conan/stable/package/c8dc3f0797f6d24f3c80634ae2854ddf9ee34334/include" -I"/home/.conan/data/zlib/1.2.11/conan/stable/package/82b1dd29b2e9143665c77ef477100c690d719cbf/include" -Wl,-rpath="/home/.conan/data/Poco/1.7.8p3/pocoproject/stable/package/da23483d46b7229cbae8615ce1ea2594635f3a5f/lib" -Wl,-rpath="/home/.conan/data/OpenSSL/1.0.2l/conan/stable/package/c8dc3f0797f6d24f3c80634ae2854ddf9ee34334/lib" -Wl,-rpath="/home/.conan/data/zlib/1.2.11/conan/stable/package/82b1dd29b2e9143665c77ef477100c690d719cbf/lib" -L"/home/.conan/data/Poco/1.7.8p3/pocoproject/stable/package/da23483d46b7229cbae8615ce1ea2594635f3a5f/lib" -L"/home/.conan/data/OpenSSL/1.0.2l/conan/stable/package/c8dc3f0797f6d24f3c80634ae2854ddf9ee34334/lib" -L"/home/.conan/data/zlib/1.2.11/conan/stable/package/82b1dd29b2e9143665c77ef477100c690d719cbf/lib" -lPocoUtil -lPocoMongoDB -lPocoNet -lPocoNetSSL -lPocoCrypto -lPocoData -lPocoDataSQLite -lPocoZip -lPocoXML -lPocoJSON -lPocoFoundation -lpthread -lrt -lssl -lcrypto -ldl -lz -D_GLIBCXX_USE_CXX11_ABI=0 -m64 -s -DNDEBUGdevc
$/home/mytimer=> cat build/conaninfo.txt
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=6.3
os=Linux
[requires]
Poco/1.Y.Z
[options]
[full_settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=6.3
os=Linux
[full_requires]
OpenSSL/1.0.2l@conan/stable:c8dc3f0797f6d24f3c80634ae2854ddf9ee34334
Poco/1.7.8p3@pocoproject/stable:da23483d46b7229cbae8615ce1ea2594635f3a5f
zlib/1.2.11@conan/stable:82b1dd29b2e9143665c77ef477100c690d719cbf
[full_options]
OpenSSL:386=False
OpenSSL:no_asm=False
OpenSSL:no_bf=False
OpenSSL:no_cast=False
OpenSSL:no_des=False
OpenSSL:no_dh=False
OpenSSL:no_dsa=False
OpenSSL:no_hmac=False
OpenSSL:no_md2=False
OpenSSL:no_md5=False
OpenSSL:no_mdc2=False
OpenSSL:no_rc2=False
OpenSSL:no_rc4=False
OpenSSL:no_rc5=False
OpenSSL:no_rsa=False
OpenSSL:no_sha=False
OpenSSL:no_sse2=False
OpenSSL:no_threads=False
OpenSSL:no_zlib=False
OpenSSL:shared=False
Poco:cxx_14=False
Poco:enable_apacheconnector=False
Poco:enable_cppparser=False
Poco:enable_crypto=True
Poco:enable_data=True
Poco:enable_data_mysql=False
Poco:enable_data_odbc=False
Poco:enable_data_sqlite=True
Poco:enable_json=True
Poco:enable_mongodb=True
Poco:enable_net=True
Poco:enable_netssl=True
Poco:enable_netssl_win=True
Poco:enable_pagecompiler=False
Poco:enable_pagecompiler_file2page=False
Poco:enable_pdf=False
Poco:enable_pocodoc=False
Poco:enable_sevenzip=False
Poco:enable_tests=False
Poco:enable_util=True
Poco:enable_xml=True
Poco:enable_zip=True
Poco:force_openssl=True
Poco:poco_unbundled=False
Poco:shared=False
zlib:shared=False
[scope]
dev=True
[recipe_hash]
[env]
$/home/mytimer=> cat main/BUILD
cc_binary(
name = "timer",
srcs = ["timer.cpp"],
)
=============================================== ===================== 现在,我想使用bazel构建工具构建mytimer项目,如下所示: $ /家庭/ mytimer => bazel build - (某些选项)// main:timer
这些选项应该是什么,以便bazel可以读取conanbuildinfo.gcc并使用它来创建可执行文件?
答案 0 :(得分:2)
我使用bazel的genrule()功能以这种方式解决我的问题:
$/home/mytimer=> cat main/BUILD
genrule(
name = "timer",
outs = ["timer.out"],
cmd = "g++ /home/mytimer/main/timer.cpp@/home/mytimer/build/conanbuildinfo.gcc -o $@ ",
)
/home/mytime=> bazel build -s //main:timer
WARNING: ignoring http_proxy in environment.
WARNING: Output base '/home/.cache/bazel/_bazel_user/274fa1325d85b25c2722794ea' is on NFS. This may lead to surprising failures and undetermined behavior.
INFO: Found 1 target...
>>>>> # //main:timer [action 'Executing genrule //main:timer']
(cd /home/.cache/bazel/_bazel_user/274fa1325d85b25c2722614/execroot/__main__ && \
exec env - \
LD_LIBRARY_PATH=<library paths>
PATH=<all other paths>
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; g++ /home/bazel/examples/cpp-tutorial/mytimer/main/timer.cpp @/home/bazel/examples/cpp-tutorial/mytimer/build/conanbuildinfo.gcc -o bazel-out/local-fastbuild/genfiles/main/timer.out ')
Target //main:timer up-to-date:
bazel-genfiles/main/timer.out
INFO: Elapsed time: 1.050s, Critical Path: 0.50s
/home/mytime=> ls -lrt bazel-out/local-fastbuild/genfiles/main/
total 212
212000 Sep 26 14:42 timer.out
/home/mytime=> ./bazel-out/local-fastbuild/genfiles/main/timer.out
Callback called after 249 milliseconds.
Callback called after 749 milliseconds.
Callback called after 1249 milliseconds.
Callback called after 1749 milliseconds.
Callback called after 2249 milliseconds.
Callback called after 2749 milliseconds.
^C
因此,通过使用genrule()功能,我们可以在bazel中执行任何shell命令。虽然这不是所谓的“bazel”方式来生成工件(genrule()到bazel与“goto”命令与C / C ++相同),在这种情况下,我没有看到任何其他选项来解决这个问题。
答案 1 :(得分:1)
您还可以为此创建自定义规则:https://docs.bazel.build/versions/master/skylark/rules.html。理想情况下,你会使用Skylark api来实现C ++规则,以防止重新实现C ++规则已经完成的所有事情,但遗憾的是api尚未完成(2017年10月)。我认为最好的跟踪错误是https://github.com/bazelbuild/bazel/issues/1624。