wangyong9999 commented on code in PR #315:
URL: https://github.com/apache/paimon-cpp/pull/315#discussion_r3974967428


##########
crates/lance_ffi/build.rs:
##########
@@ -0,0 +1,38 @@
+// 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.
+
+use std::env;
+use std::path::PathBuf;
+
+fn main() {
+    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR 
must be set");
+    let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR must be 
set"));
+    let header_path = out_dir.join("paimon_lance_ffi.h");
+    let config = 
cbindgen::Config::from_file(PathBuf::from(&crate_dir).join("cbindgen.toml"))
+        .expect("cbindgen.toml must exist at crate root");
+
+    cbindgen::Builder::new()
+        .with_crate(&crate_dir)
+        .with_config(config)
+        .generate()
+        .expect("generate paimon_lance_ffi.h")
+        .write_to_file(&header_path);
+
+    println!("cargo:include={}", out_dir.display());
+    println!("cargo:rerun-if-changed=src/lib.rs");

Review Comment:
   `cbindgen::Builder::with_crate(&crate_dir)` parses the whole crate, but the 
only source file listed here is `src/lib.rs`. Once a build script emits any 
`rerun-if-changed`, cargo stops using its default "rerun on any change" 
behaviour, so editing a signature in `reader.rs` or `writer.rs` rebuilds the 
staticlib without regenerating `paimon_lance_ffi.h`. The C++ side then compiles 
against the previous declaration and the mismatch is silent at build time.
   
   `println!("cargo:rerun-if-changed=src");` covers the whole module tree.
   



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