Skip to content
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

update servo-url and fix detection #789

Merged
merged 1 commit into from
Dec 1, 2024
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
20 changes: 11 additions & 9 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ endif()
# Boost
if(ADA_BOOST_URL)
find_package(
Boost 1.80
Boost 1.86
COMPONENTS system
)
endif(ADA_BOOST_URL)
Expand Down Expand Up @@ -258,7 +258,7 @@ if(NOT WIN32)
CPMAddPackage(
NAME corrosion
GITHUB_REPOSITORY corrosion-rs/corrosion
VERSION 0.4.4
VERSION 0.5.0
DOWNLOAD_ONLY ON
OPTIONS "Rust_FIND_QUIETLY OFF"
)
Expand All @@ -272,22 +272,24 @@ if(RUST_FOUND)
corrosion_import_crate(MANIFEST_PATH "competitors/servo-url/Cargo.toml" NO_LINKER_OVERRIDE PROFILE release)

# Check if servo-url target was created successfully
if(TARGET servo-url)
message(STATUS "servo-url target was created. Linking benchmarks and servo-url.")
target_link_libraries(bench PRIVATE servo-url)
if(TARGET servo_url)
message(STATUS "servo_url target was created. Linking benchmarks and servo_url. ")
target_link_libraries(bench PRIVATE servo_url)
target_compile_definitions(bench PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")

target_link_libraries(benchdata PRIVATE servo-url)
target_link_libraries(benchdata PRIVATE servo_url)
target_compile_definitions(benchdata PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")

target_link_libraries(bbc_bench PRIVATE servo-url)
target_link_libraries(bbc_bench PRIVATE servo_url)
target_compile_definitions(bbc_bench PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")

target_link_libraries(percent_encode PRIVATE servo-url)
target_link_libraries(percent_encode PRIVATE servo_url)
target_compile_definitions(percent_encode PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")

target_link_libraries(wpt_bench PRIVATE servo-url)
target_link_libraries(wpt_bench PRIVATE servo_url)
target_compile_definitions(wpt_bench PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")
else()
message(SEND_ERROR "Rust servo-url target was not created successfully. Likely due to a bug.")
endif()
else()
message(STATUS "Rust/Cargo is unavailable." )
Expand Down
48 changes: 24 additions & 24 deletions benchmarks/competitors/servo-url/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion benchmarks/competitors/servo-url/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "servo-url"
version = "0.1.0"
edition = "2021"

[lib]
path = "lib.rs"
crate-type = ["cdylib"]

[dependencies]
url = "2.5.3"
url = "2.5.4"
libc = "0.2"

[profile.release]
Expand Down
22 changes: 11 additions & 11 deletions benchmarks/competitors/servo-url/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use libc::{c_char, size_t};
extern crate url;
extern crate libc;

#[no_mangle]
pub unsafe extern "C" fn parse_url(raw_input: *const c_char, raw_input_length: size_t) -> *mut Url {
let input = std::str::from_utf8_unchecked(slice::from_raw_parts(raw_input as *const u8, raw_input_length));
#[unsafe(no_mangle)]
pub extern "C" fn parse_url(raw_input: *const c_char, raw_input_length: size_t) -> *mut Url {
let input = unsafe { std::str::from_utf8_unchecked(slice::from_raw_parts(raw_input as *const u8, raw_input_length)) };
// This code would assume that the URL is parsed successfully:
// let result = Url::parse(input).unwrap();
// Box::into_raw(Box::new(result))
Expand All @@ -19,26 +19,26 @@ pub unsafe extern "C" fn parse_url(raw_input: *const c_char, raw_input_length: s
}
}

#[no_mangle]
pub unsafe extern "C" fn parse_url_to_href(raw_input: *const c_char, raw_input_length: size_t) -> *const c_char {
let input = std::str::from_utf8_unchecked(slice::from_raw_parts(raw_input as *const u8, raw_input_length));
#[unsafe(no_mangle)]
pub extern "C" fn parse_url_to_href(raw_input: *const c_char, raw_input_length: size_t) -> *const c_char {
let input = unsafe { std::str::from_utf8_unchecked(slice::from_raw_parts(raw_input as *const u8, raw_input_length)) };
match Url::parse(input) {
Ok(result) => std::ffi::CString::new(result.as_str()).unwrap().into_raw(),
Err(_) => std::ptr::null_mut(),
}
}

#[no_mangle]
pub unsafe extern "C" fn free_url(raw: *mut Url) {
#[unsafe(no_mangle)]
pub extern "C" fn free_url(raw: *mut Url) {
if raw.is_null() {
return;
}

drop(Box::from_raw(raw))
unsafe { drop(Box::from_raw(raw)) }
}

#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern fn free_string(ptr: *const c_char) {
// Take the ownership back to rust and drop the owner
let _ = std::ffi::CString::from_raw(ptr as *mut _);
let _ = unsafe { std::ffi::CString::from_raw(ptr as *mut _) };
}
Loading