forked from servo/servo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
189 lines (169 loc) · 6.82 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# This provides a shell with all the necesarry packages required to run mach and build servo
# NOTE: This does not work offline or for nix-build
{
buildAndroid ? false
}:
with import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/5d67ea6b4b63378b9c13be21e2ec9d1afc921713.tar.gz";
}) {
overlays = [
(import (builtins.fetchTarball {
# Bumped the channel in rust-toolchain.toml? Bump this commit too!
url = "https://github.com/oxalica/rust-overlay/archive/0be641045af6d8666c11c2c40e45ffc9667839b5.tar.gz";
}))
];
config = {
android_sdk.accept_license = buildAndroid;
allowUnfree = buildAndroid;
};
};
let
rustToolchain = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustPlatform = makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
pkgs_gnumake_4_3 = import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/6adf48f53d819a7b6e15672817fa1e78e5f4e84f.tar.gz";
}) {};
# We need clangStdenv with:
# - clang < 16 (#30587)
# - clang < 15 (#31059)
# - glibc 2.38 (#31054)
llvmPackages = llvmPackages_14;
stdenv = llvmPackages.stdenv;
buildToolsVersion = "34.0.0";
androidComposition = androidenv.composeAndroidPackages {
buildToolsVersions = [ buildToolsVersion ];
includeEmulator = true;
platformVersions = [ "33" ];
includeSources = false;
includeSystemImages = true;
systemImageTypes = [ "google_apis" ];
abiVersions = [ "x86" "armeabi-v7a" ];
includeNDK = true;
ndkVersion = "26.2.11394342";
useGoogleAPIs = false;
useGoogleTVAddOns = false;
includeExtras = [
"extras;google;gcm"
];
};
androidSdk = androidComposition.androidsdk;
# Required by ./mach build --android
androidEnvironment = lib.optionalAttrs buildAndroid rec {
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${buildToolsVersion}/aapt2";
};
in
stdenv.mkDerivation (androidEnvironment // {
name = "servo-env";
buildInputs = [
# Native dependencies
fontconfig freetype libunwind
xorg.libxcb
xorg.libX11
gst_all_1.gstreamer
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-ugly
rustup
taplo
cargo-deny
llvmPackages.bintools # provides lld
udev # Needed by libudev-sys for GamePad API.
# Build utilities
cmake dbus gcc git pkg-config which llvm perl yasm m4
# Ensure the Python version is same as the one in `.python-version` file so
# that `uv` will just symlink to the one in nix store. Otherwise `uv` will
# download a pre-built binary that won't work on nix.
# FIXME: dbus python module needs to be installed into the virtual environment.
python311
uv
# This pins gnumake to 4.3 since 4.4 breaks jobserver
# functionality in mozjs and causes builds to be extremely
# slow as it behaves as if -j1 was passed.
# See https://github.com/servo/mozjs/issues/375
pkgs_gnumake_4_3.gnumake
(rustPlatform.buildRustPackage {
name = "crown";
src = ./support/crown;
doCheck = false;
cargoLock = {
# crown is not in our Cargo workspace, so this only pulls crown and crown’s dependencies
# into the Nix store, not Servo and Servo’s dependencies.
lockFile = ./support/crown/Cargo.lock;
};
RUSTC_BOOTSTRAP = "crown";
})
] ++ (lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.AppKit
]) ++ (lib.optionals buildAndroid [
# for android builds
openjdk17_headless
androidSdk
]);
LIBCLANG_PATH = lib.makeLibraryPath [ llvmPackages.clang-unwrapped.lib ];
# Allow cargo to download crates
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
# Enable colored cargo and rustc output
TERMINFO = "${ncurses.out}/share/terminfo";
# Provide libraries that aren’t linked against but somehow required
LD_LIBRARY_PATH = lib.makeLibraryPath [
# Fixes missing library errors
xorg.libXcursor xorg.libXrandr xorg.libXi libxkbcommon
# [WARN script::dom::gpu] Could not get GPUAdapter ("NotFound")
# TLA Err: Error: Couldn't request WebGPU adapter.
vulkan-loader
];
shellHook = ''
# Fix invalid option errors during linking
# https://github.com/mozilla/nixpkgs-mozilla/commit/c72ff151a3e25f14182569679ed4cd22ef352328
unset AS
# Compiling programs under Nix sets the interpreter (ELF INTERP) and rpath (ELF DT_RUNPATH [1])
# to ensure that it can find the needed (ELF DT_NEEDED) libraries in the Nix store.
#
# This is good on NixOS, but bad everywhere else. Using the Nix interpreter makes the programs
# dependent on the Nix store, making them impossible to distribute and run on other machines
# without `nix bundle`. Even on the same machine, the program will crash in a variety of ways
# because of the “OpenGL problem” [2] and other mismatches in X11 and Wayland libraries. Worse
# still, it makes everyone else suffer the problems NixOS has, like needing $LD_LIBRARY_PATH
# (see above) and needing to disable rust-lld (servo#30123).
#
# We can make the programs independent of Nix by resetting $NIX_DYNAMIC_LINKER to the system
# interpreter, setting $NIX_DONT_SET_RPATH to prevent the clang and ld wrappers from adding
# -rpath options to $NIX_LDFLAGS [3][4], and removing any -rpath options that get added by
# clangStdenv despite $NIX_DONT_SET_RPATH.
#
# This is comparable to fixing target/*/servo after the fact with:
#
# patchelf --remove-rpath --set-interpreter $(patchelf --print-interpreter /usr/bin/env)
#
# [1] DT_RPATH breaks LD_LIBRARY_PATH and is no longer used
# https://medium.com/obscure-system/rpath-vs-runpath-883029b17c45
# [2] “Using Nix on non-NixOS distros, it’s common to see GL application errors:”
# https://github.com/nix-community/nixGL
# [3] https://ryantm.github.io/nixpkgs/stdenv/stdenv/#bintools-wrapper
# [4] https://matklad.github.io/2022/03/14/rpath-or-why-lld-doesnt-work-on-nixos.html
if ! [ -e /etc/NIXOS ]; then
set -- $NIX_LDFLAGS
for i; do
shift
if [ "$i" = -rpath ]; then
shift
else
set -- "$@" "$i"
fi
done
export NIX_DYNAMIC_LINKER=$(patchelf --print-interpreter /usr/bin/env)
export NIX_DONT_SET_RPATH=1
export NIX_LDFLAGS="$@"
# Don’t pollute ~/.rustup with toolchains installed by nixpkgs rustup, because they
# get patched in a way that makes them dependent on the Nix store.
repo_root=$(git rev-parse --show-toplevel)
export RUSTUP_HOME=$repo_root/.rustup
fi
'';
})