-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from ZettaScaleLabs/prep-safer-ffi
Release 6.1.1
- Loading branch information
Showing
36 changed files
with
460 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ crate-type = ["cdylib", "staticlib"] | |
|
||
|
||
[dependencies] | ||
stabby = { path = "../../stabby/" } | ||
stabby.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,13 @@ | |
// Pierre Avital, <[email protected]> | ||
// | ||
|
||
use std::{ | ||
fmt::Write as FmtWrite, | ||
fs::File, | ||
io::{BufWriter, Write}, | ||
path::PathBuf, | ||
}; | ||
|
||
fn u(mut i: u128) -> String { | ||
let mut result = "UTerm".into(); | ||
let mut ids = Vec::new(); | ||
|
@@ -26,35 +33,89 @@ fn u(mut i: u128) -> String { | |
result | ||
} | ||
|
||
fn main() { | ||
use std::{ | ||
fs::File, | ||
io::{BufWriter, Write}, | ||
path::PathBuf, | ||
}; | ||
fn typenum_unsigned() -> std::io::Result<()> { | ||
const SEQ_MAX: u128 = 1000; | ||
let padding_rs = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("unsigned.rs"); | ||
let mut padding_file = BufWriter::new(File::create(padding_rs).unwrap()); | ||
let filename = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("unsigned.rs"); | ||
let mut file = BufWriter::new(File::create(filename).unwrap()); | ||
for i in 0..=SEQ_MAX { | ||
let u = u(i); | ||
writeln!(padding_file, "/// {i}\npub type U{i} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ux{i:X} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ub{i:b} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U{i} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ux{i:X} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ub{i:b} = {u};")?; | ||
} | ||
for i in 0..39 { | ||
let ipow = 10u128.pow(i); | ||
let u = u(ipow); | ||
writeln!(padding_file, "/// {i}\npub type U10pow{i} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U10pow{i} = {u};")?; | ||
if ipow > SEQ_MAX { | ||
writeln!(padding_file, "/// {i}\npub type U{ipow} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ux{ipow:X} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ub{ipow:b} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U{ipow} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ux{ipow:X} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ub{ipow:b} = {u};")?; | ||
} | ||
} | ||
for i in 0..128 { | ||
let u = u(1 << i); | ||
writeln!(padding_file, "/// {i}\npub type U2pow{i} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U2pow{i} = {u};")?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn tuples(max_tuple: usize) -> std::io::Result<()> { | ||
let filename = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("tuples.rs"); | ||
let mut file = BufWriter::new(File::create(filename).unwrap()); | ||
for i in 0..=max_tuple { | ||
writeln!( | ||
file, | ||
r##"/// An ABI stable tuple of {i} elements. | ||
#[crate::stabby] | ||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub struct Tuple{i}<{generics}>({fields}); | ||
impl<{generics}> From<({generics})> for Tuple{i}<{generics}> {{ | ||
fn from(value: ({generics})) -> Self {{ | ||
let ({named_fields}) = value; | ||
Self({named_fields}) | ||
}} | ||
}} | ||
#[allow(clippy::unused_unit)] | ||
impl<{generics}> From<Tuple{i}<{generics}>> for ({generics}) {{ | ||
fn from(value: Tuple{i}<{generics}>) -> Self {{ | ||
let Tuple{i}({named_fields}) = value; | ||
({named_fields}) | ||
}} | ||
}} | ||
"##, | ||
generics = (0..i).fold(String::new(), |mut acc, it| { | ||
write!(acc, "T{it}, ").unwrap(); | ||
acc | ||
}), | ||
fields = (0..i).fold(String::new(), |mut acc, it| { | ||
write!(acc, "pub T{it}, ").unwrap(); | ||
acc | ||
}), | ||
named_fields = (0..i).fold(String::new(), |mut acc, it| { | ||
write!(acc, "field{it}, ").unwrap(); | ||
acc | ||
}), | ||
)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
typenum_unsigned().unwrap(); | ||
println!("cargo:rustc-check-cfg=cfg(stabby_max_tuple, values(any()))"); | ||
let max_tuple = std::env::var("CARGO_CFG_STABBY_MAX_TUPLE") | ||
.map_or(32, |s| s.parse().unwrap_or(32)) | ||
.max(10); | ||
tuples(max_tuple).unwrap(); | ||
println!("cargo:rustc-check-cfg=cfg(stabby_nightly, values(none()))"); | ||
println!( | ||
r#"cargo:rustc-check-cfg=cfg(stabby_check_unreachable, values(none(), "true", "false"))"# | ||
); | ||
println!(r#"cargo:rustc-check-cfg=cfg(stabby_unsafe_wakers, values(none(), "true", "false"))"#); | ||
println!( | ||
r#"cargo:rustc-check-cfg=cfg(stabby_vtables, values(none(), "vec", "btree", "no_alloc"))"# | ||
); | ||
if let Ok(toolchain) = std::env::var("RUSTUP_TOOLCHAIN") { | ||
if toolchain.starts_with("nightly") { | ||
println!("cargo:rustc-cfg=stabby_nightly"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.