Unverified Commit 1a2cead2 authored by j-k's avatar j-k Committed by GitHub
Browse files

deno: build librusty_v8 from source (#489526)

parents c14757a4 6807e697
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
Submodule build contains modified content
diff --git a/build/rust/allocator/lib.rs b/build/rust/allocator/lib.rs
index 4b834e322..1970d664e 100644
--- a/build/rust/allocator/lib.rs
+++ b/build/rust/allocator/lib.rs
@@ -87,7 +87,6 @@ mod both_allocators {
     /// rustc-generated shims we must define this symbol, since we are opting in
     /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015
     #[rustc_std_internal_symbol]
-    #[linkage = "weak"]
     fn __rust_no_alloc_shim_is_unstable_v2() {}
 
     #[cfg(not(RUST_ALLOCATOR_NIGHTLY_CAPABILITY))]
+169 −12
Original line number Diff line number Diff line
# auto-generated file -- DO NOT EDIT!
{ fetchLibrustyV8 }:

fetchLibrustyV8 {
  version = "147.0.0";
  shas = {
    x86_64-linux = "sha256-PXLRowkOBRVWeonQDTN6e4BQlSLK/kobCX7eE0Y1NLY=";
    aarch64-linux = "sha256-6jaFVmmYYOZNZmk6UHUAGyibSBQn51Ie57hB7CIZBFI=";
    x86_64-darwin = "sha256-yTrxJ5ABXg1r0myZqy4J3m/ivYdXnsgG089PrD5cMhY=";
    aarch64-darwin = "sha256-HVr7hNzZk4qQTct2Px7DvSJAnyq1duJCqJawY475SR4=";
  };
}
{
  lib,
  fetchFromGitHub,
  fetchpatch,
  rustPlatform,
  rustc,
  rustc-unwrapped,
  rust-bindgen,
  rust-analyzer,
  rustfmt,
  cargo,
  clippy,
  llvmPackages ? rustc.llvmPackages,
  pkg-config,
  stdenv,
  glib,
  glibc,
  icu,
  python3,
  gn,
  ninja,
  xcbuild,
  apple-sdk_15,
  symlinkJoin,
  deno,
}:
let
  rustToolchain = symlinkJoin {
    name = "rusty-v8-rust-toolchain";
    paths = [
      rustc
      rustc-unwrapped
      rust-bindgen
      rust-analyzer
      rustfmt
      cargo
      clippy
      llvmPackages.libclang.lib
    ];
    postBuild = ''
      mkdir -p "$out/lib/rustlib/src/rust"
      cp -r '${rustPlatform.rustcSrc}'/* "$out/lib/rustlib/src/rust/"
      chmod u+w "$out/lib/rustlib/src/rust/library/"
      ln -s '${rustPlatform.rustVendorSrc}' "$out/lib/rustlib/src/rust/library/vendor"
    '';
  };

  clangBasePath = symlinkJoin {
    name = "rusty-v8-llvm-toolchain";
    paths = [
      llvmPackages.clang-unwrapped.lib
      llvmPackages.clang
      llvmPackages.llvm
      llvmPackages.lld
    ];
    postBuild =
      if stdenv.targetPlatform.isDarwin then
        ''
          dir="$out/lib/clang/${lib.versions.major llvmPackages.clang.version}/lib/darwin/"
          mkdir -p "$dir"
          ln -s ${llvmPackages.compiler-rt}/lib/darwin/libclang_rt.osx* "$dir/libclang_rt.osx${stdenv.hostPlatform.extensions.staticLibrary}"
        ''
      else
        ''
          dir="$out/lib/clang/${lib.versions.major llvmPackages.clang.version}/lib/${stdenv.hostPlatform.config}/"
          mkdir -p "$dir"
          ln -s ${llvmPackages.compiler-rt}/lib/linux/libclang_rt.builtins-* "$dir/libclang_rt.builtins${stdenv.hostPlatform.extensions.staticLibrary}"
        '';
  };
in
rustPlatform.buildRustPackage (finalAttrs: {
  pname = "rusty-v8";
  version = "147.1.0";

  src = fetchFromGitHub {
    owner = "denoland";
    repo = "rusty_v8";
    tag = "v${finalAttrs.version}";
    fetchSubmodules = true;
    hash = "sha256-USCQtK5pJBpU1FTLMQ/bNwJXnVNkdX/EtCWqs2kVL50=";
  };

  patches = [
    ./librusty_v8_no_downloads.patch
    (fetchpatch {
      name = "chromium-146-revert-Update-fsanitizer=array-bounds-config.patch";
      # https://chromium-review.googlesource.com/c/chromium/src/+/7539408
      url = "https://chromium.googlesource.com/chromium/src/+/acb47d9a6b56c4889a2ed4216e9968cfc740086c^!?format=TEXT";
      decode = "base64 -d";
      revert = true;
      includes = [ "build/config/compiler/BUILD.gn" ];
      hash = "sha256-0yEK66IEyS8xABDHY4W8oIvl4Ga1JfL1wxQy8PhXyqI=";
    })
    ./librusty_v8_revert_-fno-lifetime-dse.patch
  ]
  ++ lib.optionals stdenv.targetPlatform.isDarwin [
    ./librusty_v8-darwin-fix-__rust_no_alloc_shim_is_unstable_v2.patch
  ];

  cargoHash = "sha256-FKwXdms9j+izRKsm5TKJ8Ct8lvBuG/tYXfNzVsbs8cM=";

  nativeBuildInputs = [
    llvmPackages.clang
    python3
    pkg-config
    llvmPackages.lld
  ]
  ++ lib.optionals stdenv.targetPlatform.isLinux [
    glibc
  ]
  ++ lib.optionals stdenv.targetPlatform.isDarwin [
    xcbuild
  ];
  buildInputs = [
    glib
    icu
  ]
  ++ lib.optionals stdenv.targetPlatform.isDarwin [
    apple-sdk_15
  ];

  env = {
    V8_FROM_SOURCE = 1;
    PYTHON = "python3";
    NINJA = lib.getExe ninja;
    GN = lib.getExe gn;
    RUSTC_BOOTSTRAP = 1;
    EXTRA_GN_ARGS = lib.concatStringsSep " " (
      [
        "use_sysroot=false" # prevent download of debian sysroot
        "clang_version=\"${lib.versions.major llvmPackages.clang.version}\""
        "rustc_version=\"${rustc.version}\""
        "rust_sysroot_absolute=\"${rustToolchain}\""
        "rust_bindgen_root=\"${rustToolchain}\""
        "use_chromium_rust_toolchain=true"
        # To accomodate our newer rustc compiler
        "removed_rust_stdlib_libs=[\"adler\"]"
        "added_rust_stdlib_libs=[\"adler2\"]"
      ]
      ++ lib.optional stdenv.targetPlatform.isDarwin "mac_deployment_target=\"${stdenv.targetPlatform.darwinMinVersion}\""
    );
    LIBCLANG_PATH = lib.makeLibraryPath [ llvmPackages.libclang ];
    CLANG_BASE_PATH = clangBasePath;
  };

  buildFeatures = [ "simdutf" ];

  checkFlags = [
    # These tests probably fail due to a more recent rustc version (upstream: 1.89.0, here: 1.93.0)
    "--skip=ui"
    "--skip=scope"
  ];

  installPhase = ''
    runHook preInstall

    cp target/*/release/gn_out/obj/librusty_v8${stdenv.hostPlatform.extensions.staticLibrary} $out

    runHook postInstall
  '';

  meta = {
    description = "Rust bindings for the V8 JavaScript engine";
    homepage = "https://github.com/denoland/rusty_v8";
    license = lib.licenses.mit;
    maintainers = deno.meta.maintainers;
    platforms = deno.meta.platforms;
  };
})
+30 −0
Original line number Diff line number Diff line
diff --git a/build.rs b/build.rs
index 970e88bb..afb92e8a 100644
--- a/build.rs
+++ b/build.rs
@@ -251,7 +251,6 @@ fn build_v8(is_asan: bool) {
     download_ninja_gn_binaries();
   }
 
-  download_rust_toolchain();
 
   // `#[cfg(...)]` attributes don't work as expected from build.rs -- they refer to the configuration
   // of the host system which the build.rs script will be running on. In short, `cfg!(target_<os/arch>)`
@@ -461,17 +460,6 @@ fn maybe_clone_repo(dest: &str, repo: &str) {
 }
 
 fn maybe_install_sysroot(arch: &str) {
-  let sysroot_path = format!("build/linux/debian_sid_{arch}-sysroot");
-  if !PathBuf::from(sysroot_path).is_dir() {
-    assert!(
-      Command::new(python())
-        .arg("./build/linux/sysroot_scripts/install-sysroot.py")
-        .arg(format!("--arch={arch}"))
-        .status()
-        .unwrap()
-        .success()
-    );
-  }
 }
 
 fn download_ninja_gn_binaries() {
+19 −0
Original line number Diff line number Diff line
Submodule build contains modified content
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index ff8022f04..59699e1d4 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -625,13 +625,6 @@ config("compiler") {
       ]
     }
 
-    # The performance improvement does not seem worth the risk. See
-    # https://crbug.com/484082200 for background and https://crrev.com/c/7593035
-    # for discussion.
-    if (!is_wasm) {
-      cflags += [ "-fno-lifetime-dse" ]
-    }
-
     # TODO(hans): Remove this once Clang generates better optimized debug info
     # by default. https://crbug.com/765793
     cflags += [
+3 −4
Original line number Diff line number Diff line
@@ -9,9 +9,7 @@
  protobuf,
  installShellFiles,
  makeBinaryWrapper,
  librusty_v8 ? callPackage ./librusty_v8.nix {
    inherit (callPackage ./fetchers.nix { }) fetchLibrustyV8;
  },
  librusty_v8 ? callPackage ./librusty_v8.nix { },
  libffi,
  sqlite,
  lld,
@@ -244,7 +242,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
  '';

  passthru = {
    updateScript = ./update/update.ts;
    updateScript = ./update.sh;
    tests = callPackage ./tests { };
    inherit librusty_v8;
  };
@@ -267,6 +265,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
    maintainers = with lib.maintainers; [
      jk
      ofalvai
      mynacol
    ];
    platforms = [
      "x86_64-linux"
Loading