2017-09-25 6 views
1

J'essaie d'utiliser Conan pour la gestion des paquets et Bazel comme outil de construction pour mes codes C++. La raison pour laquelle j'utilise conan est parce que JFrog Artifactory le supporte, que j'utilise comme Artifactory Repository.Comment utiliser Bazel comme un outil de construction dans Conan.io

Pour ce faire, je suis venu avec le plan suivant:

$/home/mytimer=> ls -lrt 
    0 Sep 25 11:57 WORKSPACE 

4096 25 septembre 12:00 build/ 4096 25 septembre 12h02 principale/

$/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 

(Ceci est après J'ai exécuté conan --install ../main)

$/home/mytimer=> cat cat main/conanfile.txt 
[requires] 
Poco/[email protected]/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/[email protected]/stable:c8dc3f0797f6d24f3c80634ae2854ddf9ee34334 
Poco/[email protected]/stable:da23483d46b7229cbae8615ce1ea2594635f3a5f 
zlib/[email protected]/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"], 
) 

================================ =================== ============== Maintenant, je veux construire le projet mytimer en utilisant l'outil de construction de bazel comme ceci: $/home/mytimer => bazel build - (quelques options)// main: timer

Que devraient être ces options pour que bazel puisse lire conanbuildinfo.gcc et l'utiliser pour créer le fichier exécutable?

+0

Je ne connais pas suffisamment bazel, mais j'imagine qu'il y aurait 2 approches: l'une serait de faire comprendre à bazel le fichier gcc généré. Pour cela, vous devrez contacter bazel (probablement dans le dépôt github bazel). L'autre approche consisterait à implémenter un générateur de bazel en mode conan. Avec ce générateur, conan pourrait directement générer un fichier que bazel comprendrait directement. A bazel un mécanisme pour inclure des fichiers qui pourraient définir des variables de construction? Comme inclure des chemins, des chemins de bibliothèques, des noms de bibliothèques, des drapeaux de compilateur? – drodri

Répondre

2

J'utilisé la fonction genrule() de Bazel pour résoudre mon problème de cette façon:

$/home/mytimer=> cat main/BUILD 
genrule(
    name = "timer", 
    outs = ["timer.out"], 
    cmd = "g++ /home/mytimer/main/[email protected]/home/mytimer/build/conanbuildinfo.gcc -o [email protected] ", 
) 
/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 

Ainsi, en utilisant la fonction de genrule(), nous pouvons exécuter une commande shell dans Bazel. Bien que ce ne soit pas une méthode dite de "bazel" pour générer des artefacts (genrule() à bazel est la même chose que la commande "goto" en C/C++, dans ce scénario, je ne vois aucune autre option pour résoudre ce problème.