Rust 条件编译问题

我在写程序(纯Rust命令行应用)时,使用了Rust crate winreg-rs

对 windows 注册表有些写入操作并放在一个函数中

并有一个对 linux 上同一个的函数

extern crate winreg;
use winreg::enums::*;
use winreg::RegKey;


extern crate serde_json;
use serde_json::Value;
use std::fs::File;

fn main()  {
    chrome_native_config();
   }

#[allow(dead_code)]
#[cfg(target_os="windows")]
fn chrome_native_config(){
    let hklm = RegKey::predef(HKEY_CURRENT_USER);
    let (key,disp) = hklm.create_subkey("SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\chrome_nativeMessaging").unwrap();

    match disp {
        REG_CREATED_NEW_KEY => println!("A new key has been created"),
        REG_OPENED_EXISTING_KEY => println!("An existing key has been opened"),
    }
    key.set_value("", &"D:\\threeday\\chrome_nativeMessaging.json").unwrap();
    let value:String = key.get_value("").unwrap();
    if value != "D:\\threeday\\chrome_nativeMessaging.json".to_string() {
        key.set_value("", &"D:\\threeday\\chrome_nativeMessaging.json").unwrap();
    }
    let f = File::create("D:\\threeday\\chrome_nativeMessaging.json").unwrap();
    let config_str=r#"
    {
    "name":"com.chrome.nativemessaging",
    "description":"Chrome native messageing api example",
    "path":"D:\\threeday\\TestWeb.exe",
    "type":"stdio",
    "allowed_origins":[
        "chrome-extension://hgibimofjkchfnpmfhnigfhkkkahlmah/"
    ]
    }"#;
    let v:Value =serde_json::from_str(config_str).unwrap();
    serde_json::to_writer(&f, &v).expect("write json failed");
}

#[cfg(target_os="linux")]
fn chrome_native_config(){
    let f = File::create("~/.config/google-chrome/NativeMessingHosts/chrome_nativeMessaging.json").unwrap();
    let config_str=r#"
    {
    "name":"chrome_nativeMessaging",
    "description":"Chrome native messageing api example",
    "path":"~/.config/google-chrome/NativeMessingHosts/TestWeb",
    "type":"stdio",
    "allowed_origins":[
        "chrome-extension://fkdghlklbgmkokmgnoanmkedekgkckkp/"
    ]
    }"#;
    let v:Value =serde_json::from_str(config_str).unwrap();
    serde_json::to_writer(&f, &v).expect("write json failed");
}

但在 linux cargo build上的编译是
image.png

请问这个 Rust 条件编译怎么处理

在本指南中,我们将比较Rust和Python编程语言。我们将讨论每种情况下的适用用例,回顾使用Rust与Python的优缺点,并说明为什么Rust可能会取代Python。