slbotbm commented on code in PR #2785:
URL: https://github.com/apache/iggy/pull/2785#discussion_r2873508398


##########
foreign/cpp/BUILD.bazel:
##########
@@ -0,0 +1,103 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library", "cc_test")
+
+genrule(
+    name = "cargo_build",
+    srcs = glob(["src/**/*.rs"]) + [
+        "Cargo.toml",
+        "Cargo.lock",
+        "build.rs",
+    ],
+    tools = [
+        "@rules_rust//tools/upstream_wrapper:cargo",
+    ],
+    outs = [
+        "libiggy_cpp.a",
+        "include/lib.rs.h",
+        "cxxbridge/rust/cxx.h",
+    ],
+    cmd = """
+        set -e
+
+        CARGO="$$(pwd)/$(execpath @rules_rust//tools/upstream_wrapper:cargo)"
+        OUT_LIB="$$(pwd)/$(location libiggy_cpp.a)"
+        OUT_RS="$$(pwd)/$(location include/lib.rs.h)"
+        OUT_CXX="$$(pwd)/$(location cxxbridge/rust/cxx.h)"
+
+        PROJECT_ROOT="$$(dirname $$(readlink -f $(location Cargo.toml)))"
+        cd "$$PROJECT_ROOT"
+
+        PROFILE="debug"
+        FLAGS=""
+        if [ "$(COMPILATION_MODE)" = "opt" ]; then
+            PROFILE="release"
+            FLAGS="--release"
+        fi
+
+        env -u PWD CARGO_TARGET_DIR="target" "$$CARGO" build $$FLAGS
+
+        cp "target/$$PROFILE/libiggy_cpp.a" "$$OUT_LIB"
+        find "target/$$PROFILE/build" -name lib.rs.h | head -n 1 | xargs -I{} 
cp {} "$$OUT_RS"
+        find "target/$$PROFILE/build" -name cxx.h    | head -n 1 | xargs -I{} 
cp {} "$$OUT_CXX"
+    """,
+    local = 1,

Review Comment:
   I changed the build step to use the system-managed cargo instead of 
downloading a completely new toolchain. Further, cargo now writes to 
bazel-managed output directories. I'll also add a comment in the README.md 
about this potential issue.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to