Skip to content

Commit

Permalink
chore: clean up & format
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jan 7, 2024
1 parent 2a06aff commit 5b32686
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 38 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ std = []
[dependencies]
derive_more = "0.99.17"
serde = { version = "1.0", optional = true, features = ["derive"] }
regex = "1.10.2"

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
Expand Down
51 changes: 15 additions & 36 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use std::{env, fmt};
use regex::Regex;
use std::fmt::{Display, Formatter};
use std::fs::File;
use std::io::Read;
use std::path::Path;
use regex::Regex;

// Taken from https://github.com/Brooooooklyn/ada-url/blob/main/ada/build.rs


use std::{env, fmt};

#[derive(Clone, Debug)]
pub struct Target {
Expand Down Expand Up @@ -57,7 +53,6 @@ pub fn target_arch(arch: &str) -> &str {
}
}


fn host_tag() -> String {
// Because this is part of build.rs, the target_os is actually the host system
if cfg!(target_os = "windows") {
Expand All @@ -69,10 +64,9 @@ fn host_tag() -> String {
} else {
panic!("host os is not supported")
}
.to_string()
.to_string()
}


/// Get NDK major version from source.properties
fn ndk_major_version(ndk_dir: &Path) -> u32 {
// Capture version from the line with Pkg.Revision
Expand All @@ -92,16 +86,7 @@ fn ndk_major_version(ndk_dir: &Path) -> u32 {
captures[1].parse().expect("could not parse major version")
}



fn main() {
println!("cargo:rerun-if-changed=deps/ada.cpp");
println!("cargo:rerun-if-changed=deps/ada.h");
println!("cargo:rerun-if-changed=deps/ada_c.h");




let target_str = env::var("TARGET").unwrap();
let target: Vec<String> = target_str.split('-').map(|s| s.into()).collect();
if target.len() < 3 {
Expand All @@ -121,9 +106,6 @@ fn main() {
abi,
};




let mut build = cc::Build::new();
build
.file("./deps/ada.cpp")
Expand All @@ -139,14 +121,13 @@ fn main() {
// Except for Emscripten target (which emulates POSIX environment), compile to Wasm via WASI SDK
// which is currently the only standalone provider of stdlib for compilation of C/C++ libraries.


match target.system.as_str() {
"android" | "androideabi" => {
let ndk = ndk();
let major = ndk_major_version(Path::new(&ndk));
if major < 22 {
build
.flag( &format!("--sysroot={}/sysroot", ndk))
build
.flag(&format!("--sysroot={}/sysroot", ndk))
.flag(&format!(
"-isystem{}/sources/cxx-stl/llvm-libc++/include",
ndk
Expand All @@ -158,7 +139,7 @@ fn main() {
build.flag(&format!("--sysroot={}/sysroot", host_toolchain));
}
}
_ =>{
_ => {
if compile_target_arch.starts_with("wasm") && compile_target_os != "emscripten" {
let wasi_sdk = env::var("WASI_SDK").unwrap_or_else(|_| "/opt/wasi-sdk".to_owned());
assert!(
Expand All @@ -172,7 +153,9 @@ fn main() {
}
_ => "wasm32-wasi",
};
println!("cargo:rustc-link-search={wasi_sdk}/share/wasi-sysroot/lib/{wasi_sysroot_lib}");
println!(
"cargo:rustc-link-search={wasi_sdk}/share/wasi-sysroot/lib/{wasi_sysroot_lib}"
);
// Wasm exceptions are new and not yet supported by WASI SDK.
build.flag("-fno-exceptions");
// WASI SDK only has libc++ available.
Expand All @@ -197,21 +180,17 @@ fn main() {
if compiler.is_like_msvc() {
build.static_crt(true);
link_args::windows! {
unsafe {
no_default_lib(
"libcmt.lib",
);
}
};
unsafe {
no_default_lib(
"libcmt.lib",
);
}
};
} else if compiler.is_like_clang() && cfg!(feature = "libcpp") {
build.cpp_set_stdlib("c++");
}

}
}




build.compile("ada");
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,9 @@ impl PartialEq for Url {
}

impl PartialOrd for Url {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { Some(self.cmp(other)) }
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Url {
Expand Down

0 comments on commit 5b32686

Please sign in to comment.