<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Rust on RenovZ&#39;s Notes</title>
    <link>/tags/rust/</link>
    <description>Recent content in Rust on RenovZ&#39;s Notes</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 24 Nov 2024 11:14:21 +0800</lastBuildDate>
    <atom:link href="/tags/rust/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How to Use Build.rs</title>
      <link>/posts/how-to-use-build.rs/</link>
      <pubDate>Sun, 24 Nov 2024 11:14:21 +0800</pubDate>
      <guid>/posts/how-to-use-build.rs/</guid>
      <description>cargo:rustc-link-lib 用于指定要链接的库。 格式：&#xA;// kind（可选）：指定库类型，如 static（静态库）、dylib（动态库，默认值）。 // name：库的名称，例如 virt。 println!(&amp;#34;cargo:rustc-link-lib={kind}={name}&amp;#34;); eg:&#xA;println!(&amp;#34;cargo:rustc-link-lib=virt&amp;#34;); // 链接动态库 libvirt println!(&amp;#34;cargo:rustc-link-lib=static=foo&amp;#34;); // 链接静态库 libfoo.a cargo:rustc-link-search 用于指定 Cargo 搜索库文件的路径。 格式：&#xA;// kind（可选）：路径类型，如 native（默认值）。 // path：库所在的路径。 println!(&amp;#34;cargo:rustc-link-search={kind}={path}&amp;#34;); eg:&#xA;println!(&amp;#34;cargo:rustc-link-search=/opt/homebrew/lib&amp;#34;); // 在该路径下搜索库 println!(&amp;#34;cargo:rustc-link-search=native=/custom/path&amp;#34;); // 指定为 native 类型路径 cargo:rerun-if-changed 告诉 Cargo，当指定的文件改变时，重新运行 build.rs。 格式：&#xA;println!(&amp;#34;cargo:rerun-if-changed={file}&amp;#34;); eg:&#xA;println!(&amp;#34;cargo:rerun-if-changed=build.rs&amp;#34;); // 当 build.rs 发生改变时重新运行 println!(&amp;#34;cargo:rerun-if-changed=src/lib.rs&amp;#34;); // 监视其他文件 cargo:rerun-if-env-changed 当指定的环境变量改变时，重新运行 build.rs。 eg:&#xA;println!(&amp;#34;cargo:rerun-if-env-changed=MY_ENV_VAR&amp;#34;); pkg-config 或其他工具输出的指令 如果使用 pkg-config，它会自动输出 cargo:rustc-link-lib 和 cargo:rustc-link-search 的指令。例如： fn main() { pkg_config::Config::new() .</description>
    </item>
  </channel>
</rss>
