Skip to content

Commit c1eb129

Browse files
authored
Version 0.1 beta 5 (#29)
* fix cross compile msvc on unix host (#28) * Remove dagerous derive debug and derive copy * Bump to version 0.1-beta.5+2.4.4 * Fix crates.io link
1 parent 789dd3f commit c1eb129

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

.github/workflows/release-and-deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jobs:
132132
Import-Module -Name PSSemVer -ErrorAction Stop
133133
try {
134134
$rawVersion = $tagName -replace '^v', ''
135+
echo "version=$rawVersion" >> $env:GITHUB_ENV
135136
$Version = [PSSemVer]::Parse($rawVersion)
136137
$prereleaseValue = ($Version.Prerelease -ne $null).ToString().ToLower()
137138
echo "prerelease=$prereleaseValue" >> $env:GITHUB_ENV
@@ -158,7 +159,7 @@ jobs:
158159
name: ${{ env.prerelease == 'true' && 'Prerelease' || 'Release' }} ${{ env.TAG_NAME }}
159160
body: |
160161
This is a **${{ env.prerelease == 'true' && 'prerelease' || 'release' }}** release of **${{ github.repository }}**.
161-
- The crate is available on [Crates.io](https://crates.io/crates/${{ github.repository.name }}).
162+
- The crate is available on [Crates.io](https://crates.io/crates/wslpluginapi-sys/${{ env.version }}).
162163
- This version provides bindings for **WSLPluginAPI v${{ env.nuget_version }}**, available on [NuGet](https://www.nuget.org/packages/Microsoft.WSL.PluginApi/${{ env.nuget_version }}).
163164
prerelease: ${{ env.prerelease == 'true' }}
164165

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default-members = ["wslpluginapi-sys"]
66

77
[workspace.package]
88
name = "wslpluginapi-sys"
9-
version = "0.1.0-beta.4+2.4.4"
9+
version = "0.1.0-beta.5+2.4.4"
1010
edition = "2021"
1111
readme = "README.md"
1212
authors = ["Mickaël Véril <mika.veril@wanadoo.fr>"]

wslpluginapi-sys/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ bindgen = "0.72"
2020
cfg-if = "1.0"
2121
constcat = "0.6"
2222

23+
[target.'cfg(unix)'.build-dependencies]
24+
cow-utils = { version = "0.1" }
25+
2326
[dependencies]
2427
libc = "0.2"
2528
struct-field-names-as-array = { version = "0.3", features = [

wslpluginapi-sys/build/header_processing.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use std::{borrow::Cow, collections::HashMap, path::Path, vec};
21
#[cfg(unix)]
3-
use std::{env, path::PathBuf};
4-
2+
use crate::WSL_PLUGIN_API_HEADER_FILE_NAME;
53
use bindgen::callbacks::{ParseCallbacks, TypeKind};
6-
74
use cfg_if::cfg_if;
5+
#[cfg(unix)]
6+
use cow_utils::CowUtils;
7+
use std::{borrow::Cow, collections::HashMap, path::Path, vec};
8+
#[cfg(unix)]
9+
use std::{env, fs, io::Write, path::PathBuf};
10+
811
#[derive(Debug)]
912
struct BindgenCallback;
1013

@@ -47,21 +50,29 @@ fn rust_to_llvm_target() -> HashMap<&'static str, &'static str> {
4750

4851
/// If the host is not Windows, replace `Windows.h` with `windows.h` in a temporary file.
4952
#[cfg(unix)]
50-
fn preprocess_header<P: AsRef<Path>>(
51-
header_path: P,
52-
) -> Result<PathBuf, Box<dyn std::error::Error>> {
53-
use std::{fs, io::Write, path::PathBuf};
54-
55-
use crate::WSL_PLUGIN_API_HEADER_FILE_NAME;
56-
53+
fn preprocess_header<'a, P: 'a + AsRef<Path>>(
54+
header_path: &'a P,
55+
) -> Result<Cow<'a, Path>, Box<dyn std::error::Error>> {
5756
let content = fs::read_to_string(&header_path)?;
58-
let modified_content = content.replace("Windows.h", "windows.h");
57+
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
58+
let new_content = if target_env == "msvc" {
59+
content.cow_replace("windows.h", "Windows.h")
60+
} else {
61+
content.cow_replace("Windows.h", "windows.h")
62+
};
5963

60-
let out_dir: PathBuf = env::var("OUT_DIR")?.into();
61-
let comp_h_file_path = out_dir.join(format!("unix_{}", WSL_PLUGIN_API_HEADER_FILE_NAME));
62-
fs::File::create(&comp_h_file_path)?.write_all(modified_content.as_bytes())?;
63-
println!("Using modified header file at: {:?}", &comp_h_file_path);
64-
Ok(comp_h_file_path)
64+
let result = match new_content {
65+
Cow::Borrowed(_) => Cow::Borrowed(header_path.as_ref()),
66+
Cow::Owned(ref modified_content) => {
67+
let out_dir: PathBuf = env::var("OUT_DIR")?.into();
68+
let out_path = out_dir.join(format!("unix_{}", WSL_PLUGIN_API_HEADER_FILE_NAME));
69+
let mut file = fs::File::create(&out_path)?;
70+
file.write_all(modified_content.as_bytes())?;
71+
println!("Using modified header file at: {:?}", &out_path);
72+
Cow::Owned(out_path)
73+
}
74+
};
75+
Ok(result)
6576
}
6677

6778
pub(crate) fn process<P: AsRef<Path>, S: AsRef<str>>(
@@ -72,14 +83,15 @@ pub(crate) fn process<P: AsRef<Path>, S: AsRef<str>>(
7283
let host = host.as_ref();
7384
let target = target.as_ref();
7485
// Here we use cow to have the same type and avoiding clowning the PathBuff
75-
cfg_if! {
76-
if #[cfg(unix)] {
77-
let header_file_path: Cow<'_, Path> = Cow::Owned(preprocess_header(header_file_path)?);
78-
}
79-
else {
80-
let header_file_path: Cow<'_, Path> = Cow::Borrowed(header_file_path.as_ref());
86+
let header_file_path: Cow<'_, Path> = {
87+
cfg_if! {
88+
if #[cfg(unix)] {
89+
preprocess_header(&header_file_path)?
90+
} else {
91+
Cow::Borrowed(header_file_path.as_ref())
92+
}
8193
}
82-
}
94+
};
8395
let mut builder = bindgen::Builder::default()
8496
.header(header_file_path.to_str().unwrap())
8597
.raw_line("use windows::core::*;")
@@ -91,8 +103,6 @@ pub(crate) fn process<P: AsRef<Path>, S: AsRef<str>>(
91103
.raw_line("#[allow(clippy::upper_case_acronyms)] type DWORD = u32;")
92104
.raw_line(r#"#[cfg(feature = "hooks-field-names")]"#)
93105
.raw_line("use struct_field_names_as_array::FieldNamesAsSlice;")
94-
.derive_debug(true)
95-
.derive_copy(true)
96106
.allowlist_item("WSL.*")
97107
.allowlist_item("Wsl.*")
98108
.clang_arg("-fparse-all-comments")

0 commit comments

Comments
 (0)