Skip to content

Truly independent web browser

LibJS: Build the standalone runtime independently of LibWeb

Timothy Flynn252f05e66d48
diff --git a/Libraries/LibJS/CMakeLists.txt b/Libraries/LibJS/CMakeLists.txt
index d9ec3abd7c0..b9493c9faf6 100644
--- a/Libraries/LibJS/CMakeLists.txt
+++ b/Libraries/LibJS/CMakeLists.txt
@@ -123,28 +123,19 @@ if (LIBJS_FOLDED_INTO_LIBWEB)
ladybird_install_library_headers(LibJS JS)
add_lagom_library_install_rules(LibJS ALIAS_NAME JS)
- # LibJSStandalone is what a JavaScript tool that does not use LibWeb links: the objects, and the runtime out of the
- # archive of LibWeb's crate, of which the tool takes only the members it references, so that building a tool never
- # builds LibWeb's C++. The tool initializes the runtime's panic hook and demangler as the crate the runtime is.
- add_rust_crate_initializer(libjs_rust)
+ # Standalone JavaScript tools link the objects and an independent runtime archive, so building them does not
+ # build LibWeb's Rust code or generate its bindings.
add_library(LibJSStandalone INTERFACE)
target_link_libraries(LibJSStandalone INTERFACE
$<TARGET_OBJECTS:LibJSObjects>
- $<TARGET_OBJECTS:libjs_rust_init>
- LibJSHeaders libweb_bindings_rust_archive AK LibCore LibCrypto LibGC LibSyntax LibTextCodec
+ LibJSHeaders libjs_rust AK LibCore LibCrypto LibGC LibSyntax LibTextCodec
)
if ((LINUX OR BSD) AND BUILD_SHARED_LIBS)
# The tool's copy of the runtime, with its Rust standard library, stays out of its dynamic symbol table, as the
- # copy in LibJS's own library does. LibWeb's directory, which imports the archive, comes after this one, so
- # the archive's name is resolved when the build is generated.
+ # copy in LibJS's own library does.
target_link_options(LibJSStandalone INTERFACE
- "LINKER:--exclude-libs,$<TARGET_FILE_NAME:libweb_bindings_rust_archive>"
+ "LINKER:--exclude-libs,$<TARGET_FILE_NAME:libjs_rust>"
)
- elseif ((LINUX OR BSD) AND NOT BUILD_SHARED_LIBS)
- # The archive carries its own copy of the Rust standard library and of the crates it shares with the Rust
- # archives of LibUnicode and the other libraries a tool links, whose exported symbols then appear twice in
- # static ELF links.
- target_link_options(LibJSStandalone INTERFACE LINKER:--allow-multiple-definition)
endif()
else()
set(SOURCES $<TARGET_OBJECTS:LibJSObjects>)
diff --git a/Libraries/LibJS/Rust/CMakeLists.txt b/Libraries/LibJS/Rust/CMakeLists.txt
index 059559783d0..2233523541b 100644
--- a/Libraries/LibJS/Rust/CMakeLists.txt
+++ b/Libraries/LibJS/Rust/CMakeLists.txt
@@ -10,12 +10,8 @@ generate_rust_ffi_headers(
LibJS/Embedding/Layout.h
)
-# The runtime crate. When LibWeb is built, LibWeb's crate builds it as a dependency, with the same features, and
-# LibWeb's library links it (Libraries/LibWeb/CMakeLists.txt).
-if (LIBJS_FOLDED_INTO_LIBWEB)
- return()
-endif()
-
+# Build the runtime independently for standalone JavaScript tools. LibWeb's crate also builds it as a dependency,
+# with the same features, for LibWeb's library (Libraries/LibWeb/CMakeLists.txt).
import_rust_crate(
MANIFEST_PATH Cargo.toml
CRATE_NAME libjs_rust
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 32aea2e0e84..197f23f3b5c 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -1170,9 +1170,6 @@ sync_rust_crate_ffi_headers(
)
add_dependencies(LibWeb libweb_rust-ffi-headers)
target_link_libraries(libweb_bindings_rust INTERFACE LibGfx LibGC LibUnicode)
-# The JavaScript tools link the LibJS runtime from this archive. It calls into LibGC and LibUnicode, so those must come
-# after the archive on the link line.
-target_link_libraries(libweb_bindings_rust_archive INTERFACE LibGC LibUnicode)
test_rust_crate(MANIFEST_PATH Bindings/Rust/Cargo.toml CRATE_NAME libweb_bindings_rust)
test_rust_crate(MANIFEST_PATH Rust/Cargo.toml CRATE_NAME libweb_rust)
diff --git a/Meta/CMake/rust_crate.cmake b/Meta/CMake/rust_crate.cmake
index 83b8866814c..41de1f34bf9 100644
--- a/Meta/CMake/rust_crate.cmake
+++ b/Meta/CMake/rust_crate.cmake
@@ -97,8 +97,7 @@ function(import_rust_crate)
_rust_crate_link_runtime_libraries(${ARG_CRATE_NAME})
# The archive on its own, without the initializer and the kept symbols of the library that imports the crate, for a
- # target that takes a crate the archive bundles out of it, as the JavaScript tools take the LibJS runtime out of
- # LibWeb's crate.
+ # target that takes a crate the archive bundles out of it.
add_library(${ARG_CRATE_NAME}_archive STATIC IMPORTED GLOBAL)
set_target_properties(${ARG_CRATE_NAME}_archive PROPERTIES IMPORTED_LOCATION "${output_lib}")
add_dependencies(${ARG_CRATE_NAME}_archive ${ARG_CRATE_NAME}-build)
@@ -136,8 +135,7 @@ endfunction()
#
# Defines the object library <crate>_init, whose one object sets up the panic hook and the demangler of the crate in
# whatever links the object. import_rust_crate() defines it for the crate it imports; a target that takes a crate out
-# of the archive of another import, as the JavaScript tools take the LibJS runtime out of LibWeb's crate, defines it for
-# that crate.
+# of the archive of another import defines it for that crate.
function(add_rust_crate_initializer crate)
set(RUST_CRATE_NAME ${crate})
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/RustCrateInit.cpp.in"
diff --git a/Meta/Linters/check_rust_process_wide_state.py b/Meta/Linters/check_rust_process_wide_state.py
index 2aa2b8eda27..01f9602d234 100755
--- a/Meta/Linters/check_rust_process_wide_state.py
+++ b/Meta/Linters/check_rust_process_wide_state.py
@@ -44,9 +44,8 @@ ALLOWED = {
IN_ONE_LIBRARY = {
"libjs_rust": (
{"libweb_bindings_rust"},
- "a dependency of libweb_bindings_rust alone, whose archive both LibWeb's library and the JavaScript tools "
- "link in a build with LibWeb; a build without LibWeb imports the crate itself, as the one Rust archive of "
- "LibJS's library (Libraries/LibJS/CMakeLists.txt)",
+ "a dependency of libweb_bindings_rust alone, whose archive LibWeb's library links; standalone JavaScript "
+ "tools link the crate independently, and no process uses both (Libraries/LibJS/CMakeLists.txt)",
),
"libweb_rust": (
{"libweb_bindings_rust"},