#!/bin/bash if [ -n "${ZSH_VERSION:-}" ]; then exec /bin/bash "$0" "$@"; fi echo "Recommended for development: Newest Debian, Ubuntu, Fedora or Arch/Omarchy amd64 based distro, directly to SSD disk or dual boot, not VM. Works fast." echo "Note1: If you use other locale than en_US.UTF-8 , you need to additionally install en_US.UTF-8" echo " so that MongoDB works correctly: Debian/Ubuntu 'sudo dpkg-reconfigure locales'," echo " Arch/Omarchy: uncomment en_US.UTF-8 in /etc/locale.gen and run 'sudo locale-gen'." echo " You can still use any other locale as your main locale." echo "Note2: Console output is also logged to the operation-specific path printed below." echo "Note3: All logs use .tools/log//YYYY-MM-DD_HH-MM-SS/." echo " .tools/log/ inside this repository. The path is printed when a run" echo " starts." echo "Note4: Two build directories, and they are not the same thing:" echo " .build/ - the RELEASE bundle, from 'meteor build .build --directory'." echo " .build/bundle is what is deployed, tested and packaged." echo " _build/ - rspack's compiled output, written by ANY Meteor compile." echo " Meteor reads its main modules from _build/main-prod/, so" echo " it is a handoff, not a leftover: it is gitignored but must" echo " NOT be added to .meteorignore (see the note in that file)." echo " Both are generated. Never edit them, never commit them, and skip them" echo " in any tool that walks the repo - _build holds a second copy of every" echo " source file." # Give the Meteor build tool and Node processes a larger heap so long # development sessions and test runs don't crash with # "FATAL ERROR: Ineffective mark-compacts near heap limit - JavaScript heap out # of memory". TOOL_NODE_FLAGS controls the Meteor command-line/build process # (the one that hits the limit during `meteor run`/`meteor test`/`meteor build`); # NODE_OPTIONS covers child Node/rspack processes. Defaults use available # memory and honor any value already exported. # The size is worked out from the machine rather than fixed at 8192, because # 8192 is where a build died: # # FATAL ERROR: Ineffective mark-compacts near heap limit # Allocation failed - JavaScript heap out of memory # # at 8146 MB of an 8192 MB limit, on a machine with 30 GiB of RAM. The build had # not run out of memory, it had run out of the ceiling this line gave it - and # because that ceiling was a constant, the same number was too small on a large # machine and too large on a small one. # # Half of available host or cgroup RAM, capped at 16384. Half leaves the # rest usable while a build runs; a small machine # gets a proportionally smaller heap, and the ceiling is there because a heap # larger than that means something is wrong rather than something is big. At # 16 GiB this works out to 8192, which is exactly what was hard-coded here # before, so nothing changes on the machine that value was chosen for. # # Anything already exported still wins, which is how to override it. # Always computed, never conditionally: if only ONE of the two variables were # already set, skipping this would leave the other with an empty size and Node # would be handed "--max-old-space-size=". _mem_total_mb=$(awk '/^MemTotal:/ { print int($2 / 1024) }' /proc/meminfo 2>/dev/null) # Containers and Flatpak may expose host MemTotal while enforcing a smaller cgroup. # Use the smaller finite cgroup limit so the heap cannot exceed its real sandbox. for _cg_file in /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory/memory.limit_in_bytes; do [ -r "$_cg_file" ] || continue _cg_bytes=$(cat "$_cg_file" 2>/dev/null || true) case "$_cg_bytes" in ''|max|*[!0-9]*) continue ;; esac _cg_mb=$(( _cg_bytes / 1048576 )) [ "$_cg_mb" -gt 0 ] && { [ -z "${_mem_total_mb:-}" ] || [ "$_cg_mb" -lt "$_mem_total_mb" ]; } && _mem_total_mb=$_cg_mb break done # macOS has no /proc; hw.memsize is bytes. [ -n "${_mem_total_mb:-}" ] || _mem_total_mb=$(( $(sysctl -n hw.memsize 2>/dev/null || echo 0) / 1048576 )) [ "${_mem_total_mb:-0}" -gt 0 ] 2>/dev/null || _mem_total_mb=16384 _heap_mb=$(( _mem_total_mb / 2 )) [ "$_heap_mb" -gt 16384 ] && _heap_mb=16384 if [ -z "${TOOL_NODE_FLAGS:-}${NODE_OPTIONS:-}" ]; then echo "Node heap limit for builds: ${_heap_mb} MB (half of ${_mem_total_mb} MB of RAM)." echo " Override by exporting TOOL_NODE_FLAGS and NODE_OPTIONS yourself." fi export TOOL_NODE_FLAGS="${TOOL_NODE_FLAGS:---max-old-space-size=$_heap_mb}" export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=$_heap_mb}" # Every log this script writes goes into a `log///