diff --git a/.gitignore b/.gitignore index 35bed0accdaa274f5966ca5b4b7180106325449b..1c9730a5ad57cd70613c0692529bcb1ccf056d59 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ build/ .pydevproject Makefile .test_env/ + +*~ +bazel-* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 942669c41ff154c91e88c937739b0f604f21d545..b9902a863d864b28f0fad0fefe64248e356010e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,8 @@ - repo: https://github.com/reyoung/mirrors-yapf.git sha: v0.13.2 hooks: - - id: yapf + - id: yapf + files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$ # Bazel BUILD files follow Python syntax. - repo: https://github.com/pre-commit/pre-commit-hooks sha: 7539d8bd1a00a3c1bfd34cdb606d3a6372e83469 hooks: diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000000000000000000000000000000000000..d6ae2af8eb678a2e399220abefe825ab3975ff69 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,17 @@ +# External dependency to Google protobuf. +http_archive( + name = "protobuf", + url = "http://github.com/google/protobuf/archive/v3.1.0.tar.gz", + sha256 = "0a0ae63cbffc274efb573bdde9a253e3f32e458c41261df51c5dbc5ad541e8f7", + strip_prefix = "protobuf-3.1.0", +) + +# External dependency to gtest 1.7.0. This method comes from +# https://www.bazel.io/versions/master/docs/tutorial/cpp.html. +new_http_archive( + name = "gtest", + url = "https://github.com/google/googletest/archive/release-1.7.0.zip", + sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0", + build_file = "third_party/gtest.BUILD", + strip_prefix = "googletest-release-1.7.0", +) diff --git a/doc/getstarted/build_and_install/docker_install_en.rst b/doc/getstarted/build_and_install/docker_install_en.rst index 1ab6fc6a728f68b16d798a577da2896481eb17d1..feb027ccbbcdb68766e3462f0b8180e3734ef9c7 100644 --- a/doc/getstarted/build_and_install/docker_install_en.rst +++ b/doc/getstarted/build_and_install/docker_install_en.rst @@ -104,3 +104,70 @@ container: Then we can direct our Web browser to the HTML version of source code at http://localhost:8088/paddle/ + + +Development Using Docker +------------------------ + +Develpers can work on PaddlePaddle using Docker. This allows +developers to work on different platforms -- Linux, Mac OS X, and +Windows -- in a consistent way. + +The general development workflow with Docker and Bazel is as follows: + +1. Get the source code of Paddle: + + .. code-block:: bash + + git clone --recursive https://github.com/paddlepaddle/paddle + + +2. Build a development Docker image `paddle:dev` from the source code. + This image contains all the development tools and dependencies of + PaddlePaddle. + + + .. code-block:: bash + + cd paddle + docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile . + + +3. Run the image as a container and mounting local source code + directory into the container. This allows us to change the code on + the host and build it within the container. + + .. code-block:: bash + + docker run \ + -d # run the container in background mode \ + --name paddle # we can run a nginx container to serve documents \ + -p 2022:22 # so we can SSH into this container \ + -v $PWD:/paddle # mount the source code \ + -v $HOME/.cache/bazel:/root/.cache/bazel # mount Bazel cache \ + paddle:dev + +4. SSH into the container: + + .. code-block:: bash + + ssh root@localhost -p 2022 + +5. We can edit the source code in the container or on this host. Then + we can build using cmake + + .. code-block:: bash + + cd /paddle # where paddle source code has been mounted into the container + mkdir -p build + cd build + cmake -DWITH_TESTING=ON .. + make -j `nproc` + CTEST_OUTPUT_ON_FAILURE=1 ctest + + or Bazel in the container: + + .. code-block:: bash + + cd /paddle + bazel test ... diff --git a/third_party/gtest.BUILD b/third_party/gtest.BUILD new file mode 100644 index 0000000000000000000000000000000000000000..3e68a1d879311de905fab2f4cd3486a4c72a3532 --- /dev/null +++ b/third_party/gtest.BUILD @@ -0,0 +1,14 @@ +cc_library( + name = "main", + srcs = glob( + ["src/*.cc"], + exclude = ["src/gtest-all.cc"] + ), + hdrs = glob([ + "include/**/*.h", + "src/*.h" + ]), + copts = ["-Iexternal/gtest/include"], + linkopts = ["-pthread"], + visibility = ["//visibility:public"], +) diff --git a/third_party/protobuf_test/BUILD b/third_party/protobuf_test/BUILD new file mode 100644 index 0000000000000000000000000000000000000000..46f769da5f5004ef2c5f6ecee43bc8965c1d811d --- /dev/null +++ b/third_party/protobuf_test/BUILD @@ -0,0 +1,27 @@ +licenses(["notice"]) # Apache 2.0 + +load("@protobuf//:protobuf.bzl", "cc_proto_library") + +cc_proto_library( + name = "example_proto", + srcs = ["example.proto"], + protoc = "@protobuf//:protoc", + default_runtime = "@protobuf//:protobuf", +) + +cc_library( + name = "example_lib", + srcs = ["example_lib.cc"], + hdrs = ["example_lib.h"], + deps = [":example_proto"], +) + +cc_test( + name = "example_lib_test", + srcs = ["example_lib_test.cc"], + copts = ["-Iexternal/gtest/include"], + deps =[ + "@gtest//:main", + ":example_lib", + ], +) diff --git a/third_party/protobuf_test/README.md b/third_party/protobuf_test/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e8bdeee6fee66ef79d0b813b4d8dfa4c180754c6 --- /dev/null +++ b/third_party/protobuf_test/README.md @@ -0,0 +1 @@ +This package tests that Bazel can build protobuf related rules. diff --git a/third_party/protobuf_test/example.proto b/third_party/protobuf_test/example.proto new file mode 100644 index 0000000000000000000000000000000000000000..6a7eada9c14a9df5d3ef8971b636c14a11da3d11 --- /dev/null +++ b/third_party/protobuf_test/example.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package third_party.protobuf_test; + +message Greeting { + string name = 1; +} diff --git a/third_party/protobuf_test/example_lib.cc b/third_party/protobuf_test/example_lib.cc new file mode 100644 index 0000000000000000000000000000000000000000..56341a0124c0c22897aad8f5e1b85f9e28567a22 --- /dev/null +++ b/third_party/protobuf_test/example_lib.cc @@ -0,0 +1,11 @@ +#include "third_party/protobuf_test/example_lib.h" + +namespace third_party { +namespace protobuf_test { + +std::string get_greet(const Greeting& who) { + return "Hello " + who.name(); +} + +} // namespace protobuf_test +} // namespace thrid_party diff --git a/third_party/protobuf_test/example_lib.h b/third_party/protobuf_test/example_lib.h new file mode 100644 index 0000000000000000000000000000000000000000..516326e812e19eb162f5392b519904a65c66c660 --- /dev/null +++ b/third_party/protobuf_test/example_lib.h @@ -0,0 +1,13 @@ +#pragma once + +#include "third_party/protobuf_test/example.pb.h" + +#include + +namespace third_party { +namespace protobuf_test { + +std::string get_greet(const Greeting &who); + +} // namespace protobuf_test +} // namespace third_party diff --git a/third_party/protobuf_test/example_lib_test.cc b/third_party/protobuf_test/example_lib_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..6229f56e6026908fff991765bd6bdaff6f8236ac --- /dev/null +++ b/third_party/protobuf_test/example_lib_test.cc @@ -0,0 +1,15 @@ +#include "third_party/protobuf_test/example_lib.h" + +#include "gtest/gtest.h" + +namespace third_party { +namespace protobuf_test { + +TEST(ProtobufTest, GetGreet) { + Greeting g; + g.set_name("Paddle"); + EXPECT_EQ("Hello Paddle", get_greet(g)); +} + +} // namespace protobuf_test +} // namespace third_party