mirror of
https://github.com/openai/codex.git
synced 2026-09-14 11:57:03 +00:00
Working v8 musl build
This commit is contained in:
23
MODULE.bazel
23
MODULE.bazel
@@ -295,6 +295,10 @@ module.write_text(text)
|
||||
defs = Path("bazel/defs.bzl")
|
||||
text = defs.read_text()
|
||||
text = text.replace(' deps = [":define_flags", "@libcxx//:libc++"],\\n', ' deps = [":define_flags"],\\n')
|
||||
text = text.replace(
|
||||
' "//conditions:default": ["-Wl,--no-as-needed -ldl -latomic -pthread"],\\n',
|
||||
' "//conditions:default": ["-Wl,--no-as-needed -ldl -pthread"],\\n',
|
||||
)
|
||||
defs.write_text(text)
|
||||
|
||||
build = Path("BUILD.bazel")
|
||||
@@ -351,6 +355,25 @@ text = text.replace(
|
||||
)
|
||||
stack_trace.write_text(text)
|
||||
|
||||
platform_posix = Path("src/base/platform/platform-posix.cc")
|
||||
text = platform_posix.read_text()
|
||||
text = text.replace(
|
||||
'#if defined(V8_LIBC_GLIBC)\\nextern "C" void* __libc_stack_end;\\n#endif\\n',
|
||||
'',
|
||||
1,
|
||||
)
|
||||
text = text.replace(
|
||||
'#if defined(V8_LIBC_GLIBC)\\n // pthread_getattr_np can fail for the main thread.\\n // For the main thread we prefer using __libc_stack_end (if it exists) since\\n // it generally provides a tighter limit for CSS.\\n return __libc_stack_end;\\n#else\\n return nullptr;\\n#endif // !defined(V8_LIBC_GLIBC)\\n',
|
||||
' return nullptr;\\n',
|
||||
1,
|
||||
)
|
||||
text = text.replace(
|
||||
'#if defined(V8_LIBC_GLIBC)\\n // __libc_stack_end is process global and thus is only valid for\\n // the main thread. Check whether this is the main thread by checking\\n // __libc_stack_end is within the thread\\'s stack.\\n if ((base <= __libc_stack_end) && (__libc_stack_end <= stack_start)) {\\n DCHECK(MainThreadIsCurrentThread());\\n return __libc_stack_end;\\n }\\n#endif // !defined(V8_LIBC_GLIBC)\\n',
|
||||
'',
|
||||
1,
|
||||
)
|
||||
platform_posix.write_text(text)
|
||||
|
||||
thread_isolated_allocator = Path("src/libplatform/default-thread-isolated-allocator.cc")
|
||||
text = thread_isolated_allocator.read_text()
|
||||
text = text.replace(
|
||||
|
||||
53
third_party/v8/BUILD.bazel
vendored
53
third_party/v8/BUILD.bazel
vendored
@@ -1,5 +1,5 @@
|
||||
load("@rules_cc//cc:cc_static_library.bzl", "cc_static_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
@@ -42,6 +42,57 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "v8_146_4_0_public_headers",
|
||||
hdrs = ["@v8//:public_header_files"],
|
||||
includes = ["../../external/v8+/include"],
|
||||
deps = ["@v8//:rusty_v8_internal_headers"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "v8_146_4_0_smoke_test",
|
||||
srcs = ["smoke_test.cc"],
|
||||
copts = select({
|
||||
"@v8//bazel/config:is_clang": ["-std=c++20"],
|
||||
"@v8//bazel/config:is_gcc": ["-std=gnu++2a"],
|
||||
"@v8//bazel/config:is_windows": ["/std:c++20"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
tags = ["manual"],
|
||||
deps = [":v8_146_4_0_binding"],
|
||||
)
|
||||
|
||||
cc_import(
|
||||
name = "v8_146_4_0_x86_64_unknown_linux_musl_archive",
|
||||
static_library = ":v8_146_4_0_x86_64_unknown_linux_musl",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "v8_146_4_0_x86_64_unknown_linux_musl_imported",
|
||||
linkopts = [
|
||||
"-Wl,--no-as-needed",
|
||||
"-ldl",
|
||||
"-pthread",
|
||||
],
|
||||
deps = [
|
||||
":v8_146_4_0_x86_64_unknown_linux_musl_archive",
|
||||
":v8_146_4_0_public_headers",
|
||||
],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "v8_146_4_0_x86_64_unknown_linux_musl_imported_smoke_test",
|
||||
srcs = ["smoke_test.cc"],
|
||||
copts = select({
|
||||
"@v8//bazel/config:is_clang": ["-std=c++20"],
|
||||
"@v8//bazel/config:is_gcc": ["-std=gnu++2a"],
|
||||
"@v8//bazel/config:is_windows": ["/std:c++20"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
tags = ["manual"],
|
||||
deps = [":v8_146_4_0_x86_64_unknown_linux_musl_imported"],
|
||||
)
|
||||
|
||||
cc_static_library(
|
||||
name = "v8_146_4_0_aarch64_apple_darwin",
|
||||
deps = [":v8_146_4_0_binding"],
|
||||
|
||||
38
third_party/v8/smoke_test.cc
vendored
Normal file
38
third_party/v8/smoke_test.cc
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <memory>
|
||||
|
||||
#include "libplatform/libplatform.h"
|
||||
#include "v8.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
v8::V8::InitializeICUDefaultLocation(argv[0]);
|
||||
v8::V8::InitializeExternalStartupData(argv[0]);
|
||||
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
|
||||
v8::V8::InitializePlatform(platform.get());
|
||||
v8::V8::Initialize();
|
||||
|
||||
v8::Isolate::CreateParams create_params;
|
||||
create_params.array_buffer_allocator =
|
||||
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
||||
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
||||
|
||||
int exit_code = 1;
|
||||
{
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> context = v8::Context::New(isolate);
|
||||
v8::Context::Scope context_scope(context);
|
||||
|
||||
v8::Local<v8::String> source =
|
||||
v8::String::NewFromUtf8Literal(isolate, "1 + 2");
|
||||
v8::Local<v8::Script> script =
|
||||
v8::Script::Compile(context, source).ToLocalChecked();
|
||||
v8::Local<v8::Value> result = script->Run(context).ToLocalChecked();
|
||||
exit_code = result->Int32Value(context).FromMaybe(-1) == 3 ? 0 : 1;
|
||||
}
|
||||
|
||||
isolate->Dispose();
|
||||
v8::V8::Dispose();
|
||||
v8::V8::DisposePlatform();
|
||||
delete create_params.array_buffer_allocator;
|
||||
return exit_code;
|
||||
}
|
||||
Reference in New Issue
Block a user