From aa9ff14cd0696877a402435faaf8db486ce0ff89 Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Wed, 29 May 2024 21:03:38 +0200 Subject: [PATCH] Use SpiderMonkey's encoding_c instead of our own crate (#55) SpiderMonkey uses the `encoding_c` Rust crate and comes bundled with it. This lead to either duplication or linking errors when using our own crate re-exporting `encoding_c`. Instead, with this PR we just bundle a C header file for interacting with the crate's functionality, and rely on SpiderMonkey's version. --- CMakeLists.txt | 2 +- cmake/build-crates.cmake | 3 -- crates/rust-encoding/.gitignore | 1 - crates/rust-encoding/Cargo.lock | 34 ------------ crates/rust-encoding/Cargo.toml | 17 ------ crates/rust-encoding/cbindgen.toml | 54 ------------------- crates/rust-encoding/src/lib.rs | 1 - .../include}/rust-encoding.h | 3 ++ 8 files changed, 4 insertions(+), 111 deletions(-) delete mode 100644 crates/rust-encoding/.gitignore delete mode 100644 crates/rust-encoding/Cargo.lock delete mode 100644 crates/rust-encoding/Cargo.toml delete mode 100644 crates/rust-encoding/cbindgen.toml delete mode 100644 crates/rust-encoding/src/lib.rs rename {crates/rust-encoding => deps/include}/rust-encoding.h (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9218480..0691f3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ include("host_api") include("build-crates") add_library(extension_api INTERFACE include/extension-api.h runtime/encode.h) -target_link_libraries(extension_api INTERFACE rust-url rust-encoding spidermonkey) +target_link_libraries(extension_api INTERFACE rust-url spidermonkey) target_include_directories(extension_api INTERFACE include deps/include runtime) include("builtins") diff --git a/cmake/build-crates.cmake b/cmake/build-crates.cmake index 39a8645..6c8cc5d 100644 --- a/cmake/build-crates.cmake +++ b/cmake/build-crates.cmake @@ -1,5 +1,2 @@ corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/crates/rust-url/Cargo.toml NO_LINKER_OVERRIDE) set_property(TARGET rust-url PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/crates/rust-url/) - -corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/crates/rust-encoding/Cargo.toml NO_LINKER_OVERRIDE) -set_property(TARGET rust-encoding PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/crates/rust-encoding/) diff --git a/crates/rust-encoding/.gitignore b/crates/rust-encoding/.gitignore deleted file mode 100644 index eb5a316..0000000 --- a/crates/rust-encoding/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/crates/rust-encoding/Cargo.lock b/crates/rust-encoding/Cargo.lock deleted file mode 100644 index 8e0ce86..0000000 --- a/crates/rust-encoding/Cargo.lock +++ /dev/null @@ -1,34 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "encoding_c" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9af727805f3b0d79956bde5b35732669fb5c5d45a94893798e7b7e70cfbf9cc1" -dependencies = [ - "encoding_rs", -] - -[[package]] -name = "encoding_rs" -version = "0.8.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "rust-encoding" -version = "0.1.0" -dependencies = [ - "encoding_c", -] diff --git a/crates/rust-encoding/Cargo.toml b/crates/rust-encoding/Cargo.toml deleted file mode 100644 index 9419498..0000000 --- a/crates/rust-encoding/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "rust-encoding" -version = "0.1.0" -edition = "2018" - -[lib] -crate-type = ["staticlib"] - -[dependencies] -encoding_c = { version = "0.9.8", features = [] } - -[profile.release] -lto = true -panic = 'abort' - -[profile.dev] -panic = 'abort' diff --git a/crates/rust-encoding/cbindgen.toml b/crates/rust-encoding/cbindgen.toml deleted file mode 100644 index db25391..0000000 --- a/crates/rust-encoding/cbindgen.toml +++ /dev/null @@ -1,54 +0,0 @@ -language = "C++" - -header = """ -// The constructor created by cbindgen's `derive_constructor` causes this warning. -// Gecko's various uses of cbindgen silence it, so we do, too. -#ifdef __clang__ -# pragma GCC diagnostic ignored "-Wreturn-type-c-linkage" -#endif -""" - -pragma_once = true -include_guard = "rust_encoding_bindings_h" - -autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" - -include_version = false -namespace = "jsencoding" -using_namespaces = [] -sys_includes = [] -includes = [] -no_includes = false -after_includes = "" - -braces = "SameLine" -line_length = 100 -tab_width = 2 -documentation = true -documentation_style = "auto" -line_endings = "LF" - -usize_is_size_t = true - -[struct] -derive_constructor = true - - -[parse] -parse_deps = true -# include = [] -exclude = [] -clean = false -extra_bindings = ["encoding_c"] - - -[export] -# A list of additional items to always include in the generated bindings if they're -# found but otherwise don't appear to be used by the public API. -# -# default: [] -include = [ - "Decoder", - "Encoder", - "BIG5_ENCODING", -] \ No newline at end of file diff --git a/crates/rust-encoding/src/lib.rs b/crates/rust-encoding/src/lib.rs deleted file mode 100644 index 76bd65e..0000000 --- a/crates/rust-encoding/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub use encoding_c; diff --git a/crates/rust-encoding/rust-encoding.h b/deps/include/rust-encoding.h similarity index 99% rename from crates/rust-encoding/rust-encoding.h rename to deps/include/rust-encoding.h index 6f67cc9..70eeea6 100644 --- a/crates/rust-encoding/rust-encoding.h +++ b/deps/include/rust-encoding.h @@ -1,3 +1,6 @@ +// NOTE: This file was generated by cbindgen for the encoding_c crate. +// Since that crate is included in SpiderMonkey, we just include the header file here. +// TODO: look into whether we can bundle the header file with SpiderMonkey's includes. // The constructor created by cbindgen's `derive_constructor` causes this warning. // Gecko's various uses of cbindgen silence it, so we do, too. #ifdef __clang__