diff --git a/README.md b/README.md index 0470449364..f97853292a 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,18 @@ is recommended. Arguments can be passed to `gn` by setting the `$GN_ARGS` environmental variable. +For Linux targets, `rusty_v8` now defaults to defining +`V8_TLS_USED_IN_LIBRARY` via GN args when building from source so the produced +static archive can be linked into downstream `cdylib`/shared-library targets. +The default injected argument is: + +```bash +GN_ARGS='extra_cflags=["-DV8_TLS_USED_IN_LIBRARY"]' +``` + +Linux prebuilt release archives published by this repository are built with +this shared-library-compatible TLS mode. + Env vars used in when building from source: `SCCACHE`, `CCACHE`, `GN`, `NINJA`, `CLANG_BASE_PATH`, `GN_ARGS` diff --git a/build.rs b/build.rs index b7af326355..a8e7af7c5b 100644 --- a/build.rs +++ b/build.rs @@ -346,10 +346,20 @@ fn build_v8(is_asan: bool) { println!("cargo:warning=Not using sccache or ccache"); } - if let Ok(args) = env::var("GN_ARGS") { - for arg in args.split_whitespace() { - gn_args.push(arg.to_string()); + // Use the shared-library-safe TLS mode by default on Linux so downstream + // cdylibs can link rusty_v8 archives. Skip injection when GN_ARGS already + // sets V8_TLS_USED_IN_LIBRARY. + let mut should_inject_tls_library_define = target_os == "linux"; + if let Ok(raw_gn_args) = env::var("GN_ARGS") + && !raw_gn_args.trim().is_empty() + { + if raw_gn_args.contains("V8_TLS_USED_IN_LIBRARY") { + should_inject_tls_library_define = false; } + gn_args.push(raw_gn_args); + } + if should_inject_tls_library_define { + gn_args.push(r#"extra_cflags=["-DV8_TLS_USED_IN_LIBRARY"]"#.to_string()); } // cross-compilation setup if target_arch == "aarch64" {