Created
December 6, 2018 16:10
-
-
Save rohansingh/62d363d4da47f0173a7243f520c0ffe4 to your computer and use it in GitHub Desktop.
Rebuilding native modules for Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package_node_modules_cmd = """ | |
mkdir -p "$@" | |
cp -pRL "external/npm/node_modules" "$(@D)" | |
""" | |
rebuild_node_modules_cmd = """ | |
NPM="$$(pwd)/$(location @nodejs//:bin/npm)" | |
( | |
cd "$(@D)" | |
# Remove known-bad dependencies. | |
rm -rf node_modules/fsevents | |
# Fetch native module binaries for Linux. We're explicitly setting | |
# --fallback-to-build=false so that we never build from source. | |
# If we build from source on macOS, we will get a macOS binary, | |
# which we don't want. | |
$$NPM rebuild \ | |
--update-binary \ | |
--target_arch=x64 \ | |
--target_platform=linux \ | |
--target_libc=glibc \ | |
--fallback-to-build=false | |
) > "$(@D)/npm.log" | |
""" | |
native.genrule( | |
name = "node_modules-rebuilt", | |
message = "Packaging node_modules for Linux", | |
srcs = [], | |
tools = [ | |
"@nodejs//:bin/npm", | |
"@npm//:node_modules", | |
], | |
outs = ["node_modules"], | |
tags = ["local"], # run without sandboxing for ~2x speedup on macOS | |
cmd = select({ | |
"@bazel_tools//src/conditions:darwin": ( | |
package_node_modules_cmd + rebuild_node_modules_cmd | |
), | |
"//conditions:default": package_node_modules_cmd, | |
}), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment