Skip to content

Remove binary packaging support #1067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions crates/gen/build.rs

This file was deleted.

13 changes: 3 additions & 10 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ impl ToTokens for RawString {
pub fn build(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
let build = parse_macro_input!(stream as BuildMacro);
let tokens = RawString(build.to_tokens_string());
let target_dir = std::env::var("PATH").expect("No `PATH` env variable set");
let end = target_dir.find(';').expect("Path not ending in `;`");
let target_dir = RawString(target_dir[..end].to_string());
let target_dir = RawString(target_dir());
let workspace_dir = RawString(workspace_dir());

let tokens = quote! {
{
Expand Down Expand Up @@ -107,7 +106,7 @@ pub fn build(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
}
}

let mut source : ::std::path::PathBuf = ::std::env::var("CARGO_MANIFEST_DIR").expect("No `CARGO_MANIFEST_DIR` env variable set").into();
let mut source : ::std::path::PathBuf = #workspace_dir.into();
source.push(".windows");

if source.exists() {
Expand All @@ -132,12 +131,6 @@ pub fn build(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {

let profile = ::std::env::var("PROFILE").expect("No `PROFILE` env variable set");
copy_to_profile(&source, &destination, &profile);

destination.push(".windows");
destination.push("winmd");
source.pop();
source.push("winmd");
copy(&source, &mut destination);
}
}
};
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/reader/src/type_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl TypeReader {
///
/// This function panics if the if the files where the windows metadata are stored cannot be read.
fn new() -> Self {
let files = crate_winmds();
let files = workspace_winmds();
let mut nested = HashMap::<Row, BTreeMap<&'static str, TypeDef>>::new();
let mut types = TypeTree::from_namespace("");
types.include = true;
Expand Down
89 changes: 40 additions & 49 deletions crates/reader/src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
use super::*;

pub fn crate_winmds() -> &'static [File] {
pub fn workspace_winmds() -> &'static [File] {
use std::{mem::MaybeUninit, sync::Once};
static ONCE: Once = Once::new();
static mut VALUE: MaybeUninit<Vec<File>> = MaybeUninit::uninit();

ONCE.call_once(|| {
// This is safe because `Once` provides thread-safe one-time initialization
unsafe { VALUE = MaybeUninit::new(get_crate_winmds()) }
});

// This is safe because `call_once` has already been called.
unsafe { &*VALUE.as_ptr() }
}

fn cargo_metadata() -> &'static str {
use std::{mem::MaybeUninit, sync::Once};
static ONCE: Once = Once::new();
static mut VALUE: MaybeUninit<String> = MaybeUninit::uninit();

ONCE.call_once(|| {
let output = std::process::Command::new(env!("CARGO"))
.arg("metadata")
.arg("--format-version=1")
.arg("--no-deps")
.arg("--offline")
.output()
.expect("Failed to run `cargo metadata`");
ONCE.call_once(|| unsafe { VALUE = MaybeUninit::new(get_workspace_winmds()) });

unsafe {
VALUE = MaybeUninit::new(
String::from_utf8(output.stdout).expect("Cargo metadata is not utf-8"),
)
}
});

// This is safe because `call_once` has already been called.
unsafe { &*VALUE.as_ptr() }
}

Expand All @@ -56,7 +27,7 @@ pub fn workspace_dir() -> String {
json[beginning_index..beginning_index + ending_index].replace("\\\\", "\\")
}

fn target_dir() -> String {
pub fn target_dir() -> String {
const JSON_KEY: &str = r#""target_directory":"#;
let json = cargo_metadata();

Expand All @@ -73,7 +44,32 @@ fn target_dir() -> String {
json[beginning_index..beginning_index + ending_index].replace("\\\\", "\\")
}

fn get_crate_winmds() -> Vec<File> {
fn cargo_metadata() -> &'static str {
use std::{mem::MaybeUninit, sync::Once};
static ONCE: Once = Once::new();
static mut VALUE: MaybeUninit<String> = MaybeUninit::uninit();

ONCE.call_once(|| {
let output = std::process::Command::new(env!("CARGO"))
.arg("metadata")
.arg("--format-version=1")
.arg("--no-deps")
.arg("--offline")
.output()
.expect("Failed to run `cargo metadata`");

unsafe {
VALUE = MaybeUninit::new(
String::from_utf8(output.stdout).expect("Cargo metadata is not utf-8"),
)
}
});

// This is safe because `call_once` has already been called.
unsafe { &*VALUE.as_ptr() }
}

fn get_workspace_winmds() -> Vec<File> {
fn push_dir(result: &mut Vec<File>, dir: &std::path::Path) {
if let Ok(files) = std::fs::read_dir(&dir) {
for file in files.filter_map(|file| file.ok()) {
Expand All @@ -93,26 +89,21 @@ fn get_crate_winmds() -> Vec<File> {

let mut result = vec![];

if let Ok(dir) = std::env::var("CARGO_MANIFEST_DIR") {
let mut dir: std::path::PathBuf = dir.into();
dir.push(".windows");
dir.push("winmd");
push_dir(&mut result, &dir);
}

let dir = std::env::var("PATH").expect("No `PATH` env variable set");
let end = dir.find(';').expect("Path not ending in `;`");
let mut dir: std::path::PathBuf = dir[..end].into();
dir.pop();
dir.pop();
let mut dir: std::path::PathBuf = workspace_dir().into();
dir.push(".windows");
dir.push("winmd");
push_dir(&mut result, &dir);

let mut dir: std::path::PathBuf = target_dir().into();
dir.push(".windows");
dir.push("winmd");
push_dir(&mut result, &dir);
if !result.iter().any(|file| file.name.starts_with("Windows.")) {
result.push(File::from_bytes(
"Windows.Win32.winmd".to_string(),
include_bytes!("../default/Windows.Win32.winmd").to_vec(),
));
result.push(File::from_bytes(
"Windows.WinRT.winmd".to_string(),
include_bytes!("../default/Windows.WinRT.winmd").to_vec(),
));
}

result
}