feat(setup): install macOS Gazebo from a locked conda-forge environment

Homebrew rebuilds and drops the gz bottles whenever homebrew-core bumps
protobuf or abseil, which breaks the macOS Gazebo install until the pins
catch up. conda-forge keeps every package it has published, so
Tools/setup/macos/pixi.toml and its lock install the same gz, protobuf,
abseil, OpenCV and GStreamer binaries until the lock is updated on
purpose. OpenCV is the headless build, and GStreamer brings the good,
bad and ugly plugin sets the gz camera plugin's pipeline uses.

macos.sh installs the environment with pixi and loads it from the venv
activation through a small script, since pixi shell-hook would export
the installing shell's PATH. The build and the gz launch do not depend
on that activation: CMake searches the environment like it pins the
.venv Python, and px4-rc.gzsim sources gz_env.sh before it looks for
gz, which loads the environment when it is not already active and puts
its lib dir ahead of Homebrew's in the dyld fallback path.
conda-forge's gz-transport13 does not pull in cppzmq, so the manifest
lists it.

The osrf/simulation pin, the protobuf pin and the weekly bot that
refreshed them are removed. The homebrew-core commit moves into
homebrew-pins.txt unchanged.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche committed 2026-09-26 15:12:00 -07:00
1 parent de9c69316e
commit a8b0e91ebe
15 files changed
+11219 -584

No files matched your search

+4 -2
View File
@@ -31,7 +31,7 @@ jobs:
uses: actions/cache@v5
with:
path: ~/Library/Caches/Homebrew/downloads
key: macos-homebrew-${{ runner.arch }}-${{ hashFiles('Tools/setup/macos.sh', 'Tools/setup/macos_ci_pins.sh', 'Tools/setup/homebrew-pins.txt', 'Tools/setup/protobuf-pin.txt', 'Tools/setup/gz-tap-pin.txt') }}
key: macos-homebrew-${{ runner.arch }}-${{ hashFiles('Tools/setup/macos.sh', 'Tools/setup/macos_ci_pins.sh', 'Tools/setup/homebrew-pins.txt') }}
restore-keys: |
macos-homebrew-${{ runner.arch }}-
@@ -61,7 +61,9 @@ jobs:
max-size: 200M
- name: Build px4_sitl
run: make px4_sitl
run: |
source .venv/bin/activate
make px4_sitl
- name: Cache - Stats after px4_sitl
run: ccache -s
@@ -1,64 +0,0 @@
name: macOS - Refresh gz tap pin
# Tools/setup/macos.sh pins osrf/simulation to Tools/setup/gz-tap-pin.txt so
# --sim-tools pours Gazebo bottles instead of compiling them, and protobuf to
# Tools/setup/protobuf-pin.txt so those bottles' generated headers still
# compile (see those files). OSRF advances the tap several times a week and
# homebrew-core moves protobuf on its own schedule, so once a week this moves
# the tap pin to the newest commit whose Gazebo formulae are all bottled,
# repoints the protobuf pin at whatever those bottles were built against, and
# opens a PR for it. Tools/ci/refresh_gz_tap_pin.rb does the work under
# Homebrew's Ruby and can be run by hand on any Mac.
on:
schedule:
- cron: '0 9 * * 1' # Mondays at 09:00 UTC
workflow_dispatch:
permissions:
contents: read
jobs:
refresh:
# Same runner as the MacOS build.
runs-on: macos-15
steps:
- uses: actions/checkout@v6
- name: Find the newest fully bottled osrf/simulation commit
id: pin
env:
# Walking homebrew-core's protobuf history goes through the GitHub
# API, which is rate limited per IP for runners without this.
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: brew ruby Tools/ci/refresh_gz_tap_pin.rb
- name: Open PR with the new pins
if: steps.pin.outputs.needs_bump == 'true'
uses: peter-evans/create-pull-request@v8
with:
# The PX4BuildBot PAT rather than GITHUB_TOKEN so the PR runs the
# MacOS build workflow, which is what verifies the new pin.
token: ${{ secrets.PX4BUILTBOT_PERSONAL_ACCESS_TOKEN }}
author: ${{ secrets.PX4BUILDBOT_USER }} <${{ secrets.PX4BUILDBOT_EMAIL }}>
committer: ${{ secrets.PX4BUILDBOT_USER }} <${{ secrets.PX4BUILDBOT_EMAIL }}>
branch: px4buildbot/gz-tap-pin
delete-branch: true
add-paths: |
Tools/setup/gz-tap-pin.txt
Tools/setup/protobuf-pin.txt
commit-message: "build(macos): ${{ steps.pin.outputs.summary }}"
title: "build(macos): ${{ steps.pin.outputs.summary }}"
body: |
Weekly check of the two macOS Gazebo pins. `Tools/setup/gz-tap-pin.txt` holds osrf/simulation at the newest commit where every formula `macos.sh --sim-tools` poured at the previous pin still has a bottle Homebrew pours on macos-15 and every bottle tarball is still served. `Tools/setup/protobuf-pin.txt` holds protobuf at the version those bottles were built against, which is the only one their generated headers compile against.
| pin | from | to |
| --- | --- | --- |
| osrf/simulation | `${{ steps.pin.outputs.old_pin }}` | `${{ steps.pin.outputs.new_pin }}` |
| protobuf | `${{ steps.pin.outputs.old_protobuf_version }}` (`${{ steps.pin.outputs.old_protobuf_pin }}`) | `${{ steps.pin.outputs.protobuf_version }}` (`${{ steps.pin.outputs.new_protobuf_pin }}`) |
An empty "to" means that pin did not move.
Tap changes: https://github.com/osrf/homebrew-simulation/compare/${{ steps.pin.outputs.old_pin }}...${{ steps.pin.outputs.new_pin || steps.pin.outputs.old_pin }}
The MacOS build legs on this PR are the real test. Merge once both pour the gz bottles without compiling anything from osrf/simulation.
+3
View File
@@ -117,6 +117,9 @@ _emscripten_sdk/
# virtual Python environment
.venv
# macOS Gazebo environment (Tools/setup/macos/pixi.toml)
.pixi
# Claude Code local settings and worktrees
.claude/settings.local.json
/.claude/worktrees/
+8
View File
@@ -184,6 +184,14 @@ set(Python3_FIND_STRATEGY LOCATION)
set(Python3_FIND_FRAMEWORK LAST)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
# macOS installs Gazebo into a project-local pixi environment
# (Tools/setup/macos/pixi.toml). Search it like the .venv above, so the
# gz modules still build when the venv is not activated.
set(PX4_MACOS_GZ_PREFIX "${CMAKE_CURRENT_LIST_DIR}/Tools/setup/macos/.pixi/envs/default")
if(APPLE AND EXISTS "${PX4_MACOS_GZ_PREFIX}")
list(APPEND CMAKE_PREFIX_PATH "${PX4_MACOS_GZ_PREFIX}")
endif()
# Preserve PYTHON_EXECUTABLE as passed if any (e.g. via -D on command
# line, or from the top Makefile); or else default to what
# find_package(Python3) resolved. Promote to a CACHE FILEPATH entry so
@@ -1,6 +1,15 @@
#!/bin/sh
# shellcheck disable=SC2154
# Setup gz environment variables. This comes first because on macOS it
# also puts the gz from Tools/setup/macos/pixi.toml on PATH.
if [ -f ./gz_env.sh ]; then
. ./gz_env.sh
elif [ -f ../gz_env.sh ]; then
. ../gz_env.sh
fi
# Enforce minimum gz version as Harmonic (gz-sim8)
MIN_GZ_VERSION="8.0.0"
GZ_SIM_VERSION=$(gz sim --versions 2>/dev/null | head -n 1 | tr -d ' ')
@@ -37,14 +46,6 @@ if [ -z "${PX4_GZ_STANDALONE}" ]; then
# shellcheck disable=SC2153
if [ -z "${gz_world}" ] && [ -n "${PX4_GZ_WORLD}" ]; then
# Setup gz environment variables
if [ -f ./gz_env.sh ]; then
. ./gz_env.sh
elif [ -f ../gz_env.sh ]; then
. ../gz_env.sh
fi
echo "INFO [init] Starting gazebo with world: ${PX4_GZ_WORLDS}/${PX4_GZ_WORLD}.sdf"
${gz_command} ${gz_sub_command} --verbose=${GZ_VERBOSE:=1} -r -s "${PX4_GZ_WORLDS}/${PX4_GZ_WORLD}.sdf" &
-342
View File
@@ -1,342 +0,0 @@
# frozen_string_literal: true
# Move Tools/setup/gz-tap-pin.txt to the newest osrf/simulation commit whose
# Gazebo formulae all have a bottle Homebrew would pour on this machine, and
# Tools/setup/protobuf-pin.txt to the homebrew-core revision that installs
# the protobuf those bottles were built against.
#
# Runs under Homebrew's Ruby so it can use Homebrew's own tap, formula and
# bottle logic:
#
# brew ruby Tools/ci/refresh_gz_tap_pin.rb
#
# macos.sh --sim-tools pins the osrf/simulation tap to gz-tap-pin.txt so
# Gazebo pours from bottles even while OSRF has them pulled (see that file).
# The pin is a point in time, so this walks the tap's first-parent history
# from origin HEAD back to the current pin, checks each commit out, and asks
# Homebrew whether every osrf/simulation formula macos.sh installs, plus
# their osrf/simulation runtime dependencies, carries a bottle for this
# host. Each bottle tarball is then HEAD-requested so a bottle block whose
# tarball is gone does not count. The first commit that passes becomes the
# new pin. The tap checkout is restored on exit either way.
#
# A formula that has no bottle at the current pin either is not required to
# have one: in practice that is the gz-harmonic meta-formula, which OSRF
# never bottles and which builds in seconds. Everything that poured at the
# pin has to keep pouring.
#
# The formula names are read from macos.sh so there is no second list to
# keep in sync. The bottle tag match is Homebrew's own, which on macOS also
# accepts a bottle built on an older macOS of the same arch, so a commit
# that passes on the oldest macOS CI runs on passes on the newer ones too.
#
# Formula#bottle is deliberately not used: `brew ruby` runs in a child of
# the brew process, which has already consumed the HOMEBREW_*_DEFAULT_PREFIX
# variables Homebrew derives its default cellar from, so here every bottle
# without an explicit cellar looks like it was built in a foreign prefix.
# The tag match and the bottle URL do not depend on that.
#
# The protobuf pin is then derived from whichever gz commit ends up pinned,
# including the one already in the file: gz .pb.h gencode is a fatal error
# against any other protobuf version, and it is homebrew-core that moves
# under the pin, so this has to be rechecked even when the tap pin stays
# put. The version comes out of the gz-msgs10 bottle's install receipt, and
# the commit is the newest homebrew-core one that still installs it.
#
# Exits 0 whether or not either pin moves; only errors exit non-zero. Under
# GitHub Actions the result also lands in $GITHUB_OUTPUT as
# needs_bump=true|false, old_pin, old_protobuf_pin and old_protobuf_version,
# plus summary and whichever of new_pin, new_pin_short, new_protobuf_pin and
# protobuf_version moved. (brew scrubs the environment but forwards GITHUB_*
# whenever CI is set, which GitHub Actions does.)
require "English"
require "json"
require "net/http"
require "tmpdir"
require "utils/github"
# Everything lives here; RefreshGzTapPin.run at the bottom is the entry point.
module RefreshGzTapPin
TAP_NAME = "osrf/simulation"
ROOT_DIR = Pathname(__dir__).parent.parent.freeze
PIN_FILE = (ROOT_DIR/"Tools/setup/gz-tap-pin.txt").freeze
MACOS_SH = (ROOT_DIR/"Tools/setup/macos.sh").freeze
ROOT_FORMULA = %r{#{Regexp.escape(TAP_NAME)}/[A-Za-z0-9@._+-]+}
PROTOBUF_PIN_FILE = (ROOT_DIR/"Tools/setup/protobuf-pin.txt").freeze
# The tap formula whose generated headers PX4 compiles against. Its bottle
# is the one that records which protobuf the gencode demands.
GENCODE_FORMULA = "#{TAP_NAME}/gz-msgs10"
CORE_REPO = "Homebrew/homebrew-core"
CORE_PROTOBUF_FORMULA = "Formula/p/protobuf.rb"
# How far back in homebrew-core's protobuf history to look for the version
# the gz bottles want. OSRF rebuilds within days, so this is many months.
CORE_HISTORY = 50
module_function
def log(message)
puts "[refresh_gz_tap_pin] #{message}"
end
def die(message)
warn "[refresh_gz_tap_pin] ERROR: #{message}"
exit 1
end
def output(key, value)
log "#{key}=#{value}"
File.open(ENV.fetch("GITHUB_OUTPUT"), "a") { |f| f.puts "#{key}=#{value}" } if ENV["GITHUB_OUTPUT"]
end
# Run git in the tap clone and return its stripped output. A failure is
# fatal unless fail: false, in which case it returns nil.
def git(tap, *args, fail: true)
out = Utils.popen_read("git", "-C", tap.path.to_s, *args, err: :out).strip
return out if $CHILD_STATUS.success?
die "git #{args.join(" ")} failed in #{tap.path}: #{out}" if fail
nil
end
# Every osrf/simulation formula in the runtime closure of the roots, as
# loaded from the tap's current checkout.
def tap_formulae(tap, roots)
Formulary.clear_cache
tap.clear_cache
formulae = {}
roots.each do |name|
root = Formulary.factory(name)
deps = root.recursive_dependencies do |_, dep|
Dependable::PRUNE if dep.build? || dep.test? || dep.optional?
end
([root] + deps.map(&:to_formula)).each do |f|
formulae[f.full_name] = f if f.tap&.name == TAP_NAME
end
end
formulae
end
# The bottle this host would pour for the formula, or nil.
def bottle_for(formula)
formula.bottle_for_tag(Utils::Bottles.tag) if formula.pour_bottle?
end
# The body of a GET, or nil unless it succeeded.
def get(url)
uri = URI(url)
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
response = http.get(uri.request_uri)
return response.body if response.is_a?(Net::HTTPSuccess)
end
nil
end
# The protobuf the gz bottles at the checked out tap commit were built
# against, which is the only one their .pb.h gencode compiles against.
# Homebrew packs the versions a bottle was built with into the install
# receipt inside the tarball, so this is what the bottle really has rather
# than what the formula asks for.
def bottled_protobuf_version(tap)
Formulary.clear_cache
tap.clear_cache
formula = Formulary.factory(GENCODE_FORMULA)
bottle = bottle_for(formula)
die "#{GENCODE_FORMULA} has no bottle here, cannot tell which protobuf it needs" if bottle.nil?
receipt = Dir.mktmpdir do |dir|
tarball = File.join(dir, "bottle.tar.gz")
body = get(bottle.url)
die "could not download #{bottle.url}" if body.nil?
File.binwrite(tarball, body)
member = "#{formula.name}/#{formula.pkg_version}/INSTALL_RECEIPT.json"
out = Utils.popen_read("tar", "-xOzf", tarball, member, err: :out)
die "no #{member} in #{bottle.url}: #{out}" unless $CHILD_STATUS.success?
out
end
deps = JSON.parse(receipt)["runtime_dependencies"] || []
dep = deps.find { |d| d["full_name"] == "protobuf" }
die "#{GENCODE_FORMULA} #{formula.pkg_version} was not built against protobuf" if dep.nil?
pkg_version(dep["version"], dep["revision"])
end
# Homebrew's own version logic needs a formula in a tap, and these are
# loose files, so assemble the PkgVersion string from the two fields that
# make it up.
def pkg_version(version, revision)
revision.to_i.positive? ? "#{version}_#{revision}" : version
end
# The version homebrew-core's protobuf formula installs, as that file has
# it.
def core_protobuf_version(formula)
version = formula[%r{^\s*url\s+"\S+/v([^/"]+)/protobuf-[^"]+"}, 1]
return nil if version.nil?
pkg_version(version, formula[/^\s*revision\s+(\d+)\s*$/, 1])
end
# The newest homebrew-core commit that still installs this protobuf.
# macos.sh reads the formula out of that commit, so a version homebrew-core
# has since moved past keeps pouring its bottle instead of building.
def core_commit_for(version)
log "looking for protobuf #{version} in #{CORE_REPO}"
commits = GitHub::API.open_rest(
"https://api.github.com/repos/#{CORE_REPO}/commits" \
"?path=#{CORE_PROTOBUF_FORMULA}&per_page=#{CORE_HISTORY}",
)
commits.each do |commit|
sha = commit["sha"]
formula = get("https://raw.githubusercontent.com/#{CORE_REPO}/#{sha}/#{CORE_PROTOBUF_FORMULA}")
next if formula.nil?
found = core_protobuf_version(formula)
puts " #{found.to_s.ljust(24)} #{sha[0, 12]} #{commit.dig("commit", "committer", "date").to_s[0, 10]}"
return sha if found == version
end
die "no #{CORE_REPO} commit in the last #{CORE_HISTORY} touching " \
"#{CORE_PROTOBUF_FORMULA} installs protobuf #{version}"
end
# The pin file's one data line, "<homebrew-core commit> <protobuf version>".
def read_protobuf_pin
line = PROTOBUF_PIN_FILE.read.lines.map(&:strip).grep_v(/\A#/).grep_v(/\A\z/).first.to_s
sha, version = line.split
unless sha.to_s.match?(/\A[0-9a-f]{40}\z/) && version
die "no '<commit> <version>' line in #{PROTOBUF_PIN_FILE}"
end
[sha, version]
end
def served?(url)
uri = URI(url)
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
http.head(uri.request_uri).is_a?(Net::HTTPSuccess)
end
end
# Whether every formula that poured at the pin still pours at the checked
# out commit and every bottle tarball is still served. One line per formula.
def bottled_here?(tap, roots, exempt)
ok = true
tap_formulae(tap, roots).each_value do |f|
bottle = bottle_for(f)
state = if bottle.nil? && exempt.include?(f.full_name)
"no bottle, not required"
elsif bottle.nil?
ok = false
"no bottle"
elsif served?(bottle.url)
"bottled"
else
ok = false
"tarball missing"
end
puts " #{state.ljust(24)} #{f.full_name} #{f.pkg_version}"
end
ok
end
def run
# The osrf/simulation formulae macos.sh installs. Read from the script
# so this never drifts from PX4_SIM_BREW_PACKAGES.
roots = MACOS_SH.read.scan(ROOT_FORMULA).uniq.sort
die "macos.sh installs nothing from #{TAP_NAME}" if roots.empty?
old_pin = PIN_FILE.read.lines.map(&:strip).grep_v(/\A#/).join
die "no commit SHA in #{PIN_FILE}" unless old_pin.match?(/\A[0-9a-f]{40}\z/)
old_protobuf_pin, old_protobuf_version = read_protobuf_pin
tap = Tap.fetch(TAP_NAME)
tap.install(quiet: true) unless tap.installed?
# Homebrew 6.0+ refuses to load formulae from untrusted taps; same guard
# as macos.sh.
Homebrew::Trust.trust!(:tap, tap) if defined?(Homebrew::Trust) && !Homebrew::Trust.trusted_tap?(tap)
die "#{tap.path} has local changes, refusing to touch it" unless git(tap, "status", "--porcelain").empty?
orig_ref = git(tap, "symbolic-ref", "--quiet", "--short", "HEAD", fail: false) || git(tap, "rev-parse", "HEAD")
new_pin = nil
protobuf_version = nil
begin
git(tap, "fetch", "--quiet", "--unshallow") if git(tap, "rev-parse", "--is-shallow-repository") == "true"
git(tap, "fetch", "--quiet", "origin")
git(tap, "remote", "set-head", "origin", "--auto")
tap_head = git(tap, "rev-parse", "origin/HEAD")
if git(tap, "merge-base", "--is-ancestor", old_pin, "origin/HEAD", fail: false).nil?
die "pin #{old_pin} is not an ancestor of #{TAP_NAME} HEAD #{tap_head}, bump it by hand"
end
output "old_pin", old_pin
output "old_protobuf_pin", old_protobuf_pin
output "old_protobuf_version", old_protobuf_version
git(tap, "checkout", "--quiet", "--detach", old_pin)
exempt = tap_formulae(tap, roots).each_value.reject { |f| bottle_for(f) }.map(&:full_name)
log "not bottled at the pin either, not required: #{exempt.join(" ")}" unless exempt.empty?
candidates = git(tap, "rev-list", "--first-parent", "#{old_pin}..origin/HEAD").split
log "#{TAP_NAME} HEAD #{tap_head} is #{candidates.size} commit(s) ahead of the pin, " \
"checking newest first for #{roots.join(" ")}"
new_pin = candidates.find do |sha|
log git(tap, "log", "-1", "--format=%h %cs %s", sha)
git(tap, "checkout", "--quiet", "--detach", sha)
bottled_here?(tap, roots, exempt)
end
# Whichever commit ends up pinned decides the protobuf pin, so read it
# off the new one if there is one and off the old one otherwise.
git(tap, "checkout", "--quiet", "--detach", new_pin || old_pin)
protobuf_version = bottled_protobuf_version(tap)
ensure
git(tap, "checkout", "--quiet", orig_ref)
end
summary = []
if new_pin.nil?
log "no commit newer than the pin is fully bottled here, keeping #{old_pin}"
else
PIN_FILE.write(PIN_FILE.read.sub(old_pin, new_pin))
behind = git(tap, "rev-list", "--count", "#{new_pin}..origin/HEAD")
log "pinned #{TAP_NAME} to #{new_pin}, #{behind} commit(s) behind HEAD"
output "new_pin", new_pin
output "new_pin_short", new_pin[0, 12]
summary << "gz tap pin to #{new_pin[0, 12]}"
end
log "#{GENCODE_FORMULA} at the pin was built against protobuf #{protobuf_version}"
if protobuf_version == old_protobuf_version
log "protobuf pin already installs #{protobuf_version}, keeping #{old_protobuf_pin}"
else
new_protobuf_pin = core_commit_for(protobuf_version)
pinned = PROTOBUF_PIN_FILE.read
bumped = pinned.sub(/^#{Regexp.escape(old_protobuf_pin)}\s+\S+$/,
"#{new_protobuf_pin} #{protobuf_version}")
die "could not rewrite the pin line in #{PROTOBUF_PIN_FILE}" if bumped == pinned
PROTOBUF_PIN_FILE.write(bumped)
log "pinned protobuf #{protobuf_version} to #{CORE_REPO} #{new_protobuf_pin}"
output "new_protobuf_pin", new_protobuf_pin
output "protobuf_version", protobuf_version
summary << "protobuf pin to #{protobuf_version}"
end
if summary.empty?
output "needs_bump", "false"
return
end
output "needs_bump", "true"
output "summary", "bump #{summary.join(" and ")}"
end
end
RefreshGzTapPin.run
-9
View File
@@ -1,9 +0,0 @@
# osrf/simulation revision used by macos.sh --sim-tools.
#
# OSRF strips the gz bottle blocks within minutes of a breaking homebrew-core
# dependency bump and rebuilds them days later. The tarballs stay on S3, so
# pinning keeps the install binary instead of compiling Gazebo from source.
# Move it to the newest commit where every gz formula macos.sh installs still
# carries a bottle block. Tools/ci/refresh_gz_tap_pin.rb does that, weekly
# from .github/workflows/macos_gz_tap_pin_refresh.yml or by hand.
9403d12a474c239604243c77751fa53ad95ba16f
+3 -4
View File
@@ -1,11 +1,10 @@
# Commits macOS CI checks out before installing. A newer package is a change
# to this file, or to protobuf-pin.txt (homebrew-core) or gz-tap-pin.txt
# (osrf/simulation).
# to this file. Gazebo does not come from Homebrew; see macos/pixi.toml.
#
# Homebrew 7.0.6. The other two are the tips of those repos on 2026-09-18,
# the last day this job was green before protobuf moved.
# Homebrew 7.0.6. The others are the tips of those repos on 2026-09-18.
#
# <name> <commit>
brew 570982948a8a194f0f42f43f4a5bce2d1c9f64cb
homebrew/core 88d598cf1d2dba7063fbc29d441d072963481123
osx-cross/arm e3bb686fb159097c2fb3ee6d1acb3f7e4dd8a184
px4/px4 f78b7a3d5aa98dc23171a63f2c2958ce69f98889
+42 -119
View File
@@ -8,9 +8,8 @@
## - Cross compilers for building hardware targets using NuttX
## - With --sim-tools: Gazebo Harmonic simulation stack
##
## --sim-tools pins the osrf/simulation tap to gz-tap-pin.txt so Gazebo
## installs from bottles even while OSRF has them pulled, and protobuf to
## protobuf-pin.txt so those bottles' headers still compile.
## --sim-tools installs Gazebo from the locked conda-forge environment in
## macos/pixi.toml, and loads it with the Python venv.
##
## Homebrew 4.5+ no longer auto-resolves cross-tap dependencies, so
## every tap and package is listed explicitly here rather than hidden
@@ -144,57 +143,17 @@ fi
# Optional, but recommended additional simulation tools:
if [[ $INSTALL_SIM == "--sim-tools" ]]; then
# Simulation packages. This replaces the px4-sim / px4-sim-gazebo
# meta-formulae, which declared cross-tap dependencies that
# Homebrew 4.5+ no longer auto-resolves. Same migration pattern as
# the toolchain block above. See PX4/homebrew-px4#104 for the
# px4-dev precedent.
#
# osrf/simulation: gz-harmonic (Gazebo Harmonic meta-formula)
#
# Trust before tapping, same as the toolchain taps above. Tapping an
# untrusted tap fails, which leaves no tap clone to pin below; the
# later `brew install osrf/simulation/gz-harmonic` then taps it
# implicitly at HEAD and the pin is silently skipped.
if brew trust --help &> /dev/null; then
brew trust osrf/simulation
fi
brew_tap osrf/simulation
# OSRF drops the gz bottle blocks within minutes of a breaking
# homebrew-core dependency bump and rebuilds them days later, so an
# unpinned tap compiles Gazebo from source for a large part of the
# year. Pin unconditionally so dev machines get the same fast, binary
# install as CI. See gz-tap-pin.txt.
GZ_TAP_PIN=$(grep -v '^#' "${DIR}/gz-tap-pin.txt" | tr -d '[:space:]')
if [[ -n $GZ_TAP_PIN ]]; then
GZ_TAP_DIR=$(brew --repo osrf/simulation)
echo "[macos.sh] Pinning osrf/simulation to ${GZ_TAP_PIN}"
# brew taps are shallow clones, so the pinned commit has to be
# fetched by SHA before it can be checked out.
git -C "$GZ_TAP_DIR" fetch --quiet origin "$GZ_TAP_PIN" 2>/dev/null || true
if git -C "$GZ_TAP_DIR" checkout --quiet "$GZ_TAP_PIN"; then
# `brew update` walks local taps and would reset the pin.
# homebrew-core resolves through the JSON API, not this
# clone, so nothing else goes stale.
export HOMEBREW_NO_AUTO_UPDATE=1
else
echo "[macos.sh] WARNING: could not pin osrf/simulation to ${GZ_TAP_PIN}," \
"continuing on tap HEAD (gz may build from source)"
fi
fi
# opencv@4: the unversioned formula is OpenCV 5, which PX4-OpticalFlow
# does not build against.
# Gazebo and everything the gz modules link against (OpenCV for
# PX4-OpticalFlow, GStreamer for the camera plugin) come from the
# locked conda-forge environment in macos/pixi.toml instead of
# Homebrew. conda-forge never removes or rebuilds a published
# package, so the lock keeps installing the same gz, protobuf and
# abseil binaries. See macos/pixi.toml.
PX4_SIM_BREW_PACKAGES=(
exiftool
glog
graphviz
gstreamer
opencv@4
osrf/simulation/gz-harmonic
protobuf
pixi
)
if [[ $REINSTALL_FORMULAS == "--reinstall" ]]; then
@@ -205,75 +164,39 @@ if [[ $INSTALL_SIM == "--sim-tools" ]]; then
brew install "${PX4_SIM_BREW_PACKAGES[@]}"
fi
# Gazebo's generated headers only compile against the exact protobuf
# their gencode came from, so protobuf has to come from the
# homebrew-core revision that was current when the pinned gz bottles
# were built rather than from whatever homebrew-core ships today. See
# protobuf-pin.txt.
#
# This runs after the installs above rather than before them because
# opencv@4 depends on protobuf as well and drags in the current one:
# brew resolves a dependency against the versions recorded in the
# dependent's bottle, so an opencv bottle rebuilt against a newer
# protobuf pulls that protobuf in no matter what is installed.
# Pinning the formula instead of reinstalling it here is not an
# option either: brew refuses to install anything whose pinned
# dependency is not the current one ("You must `brew unpin
# protobuf`").
PROTOBUF_FORMULA="Formula/p/protobuf.rb"
PROTOBUF_PIN_LINE=$(grep -v -e '^#' -e '^[[:space:]]*$' "${DIR}/protobuf-pin.txt" | head -n 1)
read -r PROTOBUF_PIN PROTOBUF_PIN_VERSION <<< "$PROTOBUF_PIN_LINE" || true
if [[ -n $PROTOBUF_PIN ]]; then
CORE_TAP_DIR=$(brew --repo homebrew/core)
INSTALLED_PROTOBUF=$(brew list --versions protobuf 2> /dev/null | awk '{print $2}')
if [[ $INSTALLED_PROTOBUF == "$PROTOBUF_PIN_VERSION" ]]; then
echo "[macos.sh] protobuf ${PROTOBUF_PIN_VERSION} is what the gz bottles need, leaving it"
elif ! git -C "$CORE_TAP_DIR" rev-parse --git-dir &> /dev/null; then
# homebrew-core resolves through the JSON API by default, and a
# formula as it was at some commit can only be read from a clone.
echo "[macos.sh] WARNING: homebrew-core is not cloned here, so protobuf cannot be held" \
"at ${PROTOBUF_PIN_VERSION} and Gazebo's headers may fail to compile." \
"Run 'brew tap homebrew/core' once to enable the pin."
else
echo "[macos.sh] Installing protobuf ${PROTOBUF_PIN_VERSION} from homebrew-core ${PROTOBUF_PIN}"
PROTOBUF_TMP=$(mktemp -d)
# A clone that has not been updated since the pin was made does
# not have the commit yet.
git -C "$CORE_TAP_DIR" fetch --quiet origin "$PROTOBUF_PIN" 2> /dev/null || true
if git -C "$CORE_TAP_DIR" show "${PROTOBUF_PIN}:${PROTOBUF_FORMULA}" \
> "${PROTOBUF_TMP}/pinned.rb" 2> /dev/null; then
# Swap the formula in place rather than checking it out, so
# the clone's git state is never touched and the file comes
# back byte for byte whether or not the install works.
cp "${CORE_TAP_DIR}/${PROTOBUF_FORMULA}" "${PROTOBUF_TMP}/current.rb"
cp "${PROTOBUF_TMP}/pinned.rb" "${CORE_TAP_DIR}/${PROTOBUF_FORMULA}"
# Whatever is installed is the wrong version, and only
# reinstall replaces it; install alone would be a no-op.
if [[ -n $INSTALLED_PROTOBUF ]]; then
PROTOBUF_INSTALL="reinstall"
else
PROTOBUF_INSTALL="install"
fi
# brew reads this clone instead of the JSON API only with
# HOMEBREW_NO_INSTALL_FROM_API, and brew update would put
# the swapped formula back before the install. Without
# HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK brew would then
# see everything linked against the protobuf it just
# replaced as broken and reinstall it, which pulls the
# newer protobuf straight back in through opencv@4.
if ! HOMEBREW_NO_INSTALL_FROM_API=1 HOMEBREW_NO_AUTO_UPDATE=1 \
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 \
brew "$PROTOBUF_INSTALL" protobuf; then
echo "[macos.sh] WARNING: could not install protobuf ${PROTOBUF_PIN_VERSION}," \
"continuing on the current one (Gazebo headers may fail to compile)"
fi
cp "${PROTOBUF_TMP}/current.rb" "${CORE_TAP_DIR}/${PROTOBUF_FORMULA}"
else
echo "[macos.sh] WARNING: homebrew-core commit ${PROTOBUF_PIN} is not available," \
"continuing on the current protobuf (Gazebo headers may fail to compile)"
fi
rm -rf "$PROTOBUF_TMP"
fi
PIXI_MANIFEST="${DIR}/macos/pixi.toml"
echo "[macos.sh] Installing Gazebo from ${PIXI_MANIFEST}"
pixi install --locked --manifest-path "$PIXI_MANIFEST"
# Load the Gazebo environment with the venv, so developers keep a
# single activation step. This is written by hand rather than taken
# from `pixi shell-hook`, which exports the PATH of the shell running
# this script instead of prepending to the user's, and sources every
# package's bash completions. The activate.d scripts set the paths
# the gz CLI (ruby gems) and renderer (OGRE) need. CMake needs the
# prefix spelled out: the gz config files are found through PATH, but
# the find_path(zmq.hpp) in gz-cmake's FindCPPZMQ is not. The env
# ships its own python, so the venv's bin goes back in front of it
# afterwards.
GZ_ENV_SCRIPT="$VENV_DIR/bin/px4-gz-env.sh"
cat > "$GZ_ENV_SCRIPT" <<-EOF
export CONDA_PREFIX="${DIR}/macos/.pixi/envs/default"
export PATH="\$CONDA_PREFIX/bin:\$PATH"
export CMAKE_PREFIX_PATH="\$CONDA_PREFIX\${CMAKE_PREFIX_PATH:+:\$CMAKE_PREFIX_PATH}"
for f in "\$CONDA_PREFIX"/etc/conda/activate.d/*.sh; do
. "\$f"
done
unset f
EOF
GZ_ENV_MARKER="# px4: load the Gazebo environment"
if ! grep -qF "$GZ_ENV_MARKER" "$VENV_DIR/bin/activate"; then
cat >> "$VENV_DIR/bin/activate" <<-EOF
$GZ_ENV_MARKER
. "\$VIRTUAL_ENV/bin/px4-gz-env.sh"
PATH="\$VIRTUAL_ENV/bin:\$PATH"
export PATH
EOF
fi
# XQuartz is required for Gazebo GUI display on macOS.
File diff suppressed because it is too large. Load diff
+31
View File
@@ -0,0 +1,31 @@
# Gazebo Harmonic for macOS, installed by macos.sh --sim-tools.
#
# conda-forge keeps every build it has published, so pixi.lock installs the
# same gz, protobuf and abseil binaries until someone updates it on purpose.
# Homebrew rebuilds and drops gz bottles whenever homebrew-core bumps one of
# their dependencies. Everything the gz modules link against comes from this
# one environment so only one protobuf is ever loaded.
#
# Update the lock with: pixi update --manifest-path Tools/setup/macos/pixi.toml
[workspace]
name = "px4-macos-gz"
channels = ["conda-forge"]
platforms = ["osx-arm64", "osx-64"]
[dependencies]
gz-harmonic = "*"
# gz-transport13's CMake config needs the cppzmq target, but the
# conda-forge package does not pull it in.
cppzmq = "*"
# PX4-OpticalFlow does not build against OpenCV 5, and only needs the C++
# library: the headless build leaves out Qt 6 and the Python bindings.
libopencv = { version = "4.*", build = "headless*" }
# The gz camera plugin's pipeline uses elements from every set: appsrc and
# videoconvert (base), rtph264pay, udpsink and flvmux (good), rtmpsink
# (bad) and x264enc (ugly).
gstreamer = "*"
gst-plugins-base = "*"
gst-plugins-good = "*"
gst-plugins-bad = "*"
gst-plugins-ugly = "*"
+1 -10
View File
@@ -16,12 +16,6 @@ if ! command -v brew >/dev/null 2>&1; then
exit 1
fi
first_field() {
local file="$1"
local n="$2"
grep -v -e '^#' -e '^[[:space:]]*$' "$file" | head -n 1 | awk -v n="$n" '{print $n}'
}
pin_sha() {
local name="$1"
grep -E "^${name}[[:space:]]+" "${DIR}/homebrew-pins.txt" | awk '{print $2}'
@@ -69,11 +63,8 @@ clone_at() {
BREW_REPO=$(brew --repo)
TAPS="${BREW_REPO}/Library/Taps"
CORE_SHA=$(first_field "${DIR}/protobuf-pin.txt" 1)
GZ_SHA=$(first_field "${DIR}/gz-tap-pin.txt" 1)
checkout_brew "$(pin_sha brew)"
clone_at "${TAPS}/homebrew/homebrew-core" "https://github.com/Homebrew/homebrew-core" "$CORE_SHA"
clone_at "${TAPS}/osrf/homebrew-simulation" "https://github.com/osrf/homebrew-simulation" "$GZ_SHA"
clone_at "${TAPS}/homebrew/homebrew-core" "https://github.com/Homebrew/homebrew-core" "$(pin_sha homebrew/core)"
clone_at "${TAPS}/osx-cross/homebrew-arm" "https://github.com/osx-cross/homebrew-arm" "$(pin_sha osx-cross/arm)"
clone_at "${TAPS}/px4/homebrew-px4" "https://github.com/PX4/homebrew-px4" "$(pin_sha px4/px4)"
-24
View File
@@ -1,24 +0,0 @@
# homebrew-core revision protobuf is installed from, and the version that is.
#
# Every gz .pb.h refuses to compile against anything but the exact protobuf
# its gencode came from ("#if PROTOBUF_VERSION != ...", which is a fatal
# error, not a warning). The gz bottles gz-tap-pin.txt pins were built
# against whatever protobuf homebrew-core shipped that day, homebrew-core
# then moves protobuf on its own schedule, and OSRF rebuilds the bottles
# days later. With protobuf unpinned, every protobuf release therefore
# breaks `make px4_sitl` on macOS until OSRF catches up.
#
# macos.sh --sim-tools puts protobuf back to this homebrew-core commit once
# the rest of the simulation packages are in, so the two pins always agree
# and a protobuf release is a no-op here. Tools/ci/refresh_gz_tap_pin.rb
# reads the version out of the pinned gz-msgs10 bottle's install receipt and
# moves both pins together, weekly from
# .github/workflows/macos_gz_tap_pin_refresh.yml.
#
# Holding protobuf back holds back its ABI too: homebrew-core bottles that
# were rebuilt against a newer protobuf (of what macos.sh installs, only
# opencv@4 links it) will not load until this pin catches up. Nothing
# `make px4_sitl` builds or runs loads them.
#
# <homebrew-core commit> <protobuf version>
88d598cf1d2dba7063fbc29d441d072963481123 36.1
+7 -1
View File
@@ -85,6 +85,12 @@ To build for [other targets](../dev_setup/dev_env.md#supported-targets) you will
The `--sim-tools` flag installs Gazebo and the libraries PX4's simulation modules build against.
Gazebo does not come from Homebrew.
The script installs it from a locked [conda-forge](https://conda-forge.org/) environment, using [pixi](https://pixi.sh), into `Tools/setup/macos/.pixi`.
The lock file pins every package, so the install does not change when Homebrew updates its own Gazebo dependencies.
The build and the `make px4_sitl gz_*` targets find it on their own, like the `.venv`.
Activating `.venv` also puts it on your `PATH`, which you only need to run `gz` commands directly.
If you skipped `--sim-tools` during initial setup and want to add simulation later, re-run the setup script with the flag (it is safe to run repeatedly):
```sh
@@ -108,7 +114,7 @@ arm-none-eabi-gcc --version
cmake --version
ninja --version
# Gazebo (if --sim-tools was used)
# Gazebo (if --sim-tools was used, with .venv activated)
gz sim --versions
```
+12 -1
View File
@@ -24,10 +24,21 @@ export GZ_SIM_SERVER_CONFIG_PATH=$PX4_GZ_SERVER_CONFIG
# gobject-introspection typelibs reference libs by bare basename,
# which fails to resolve unless we add Homebrew's lib dir to the
# fallback search path. Prepend so it beats any system-placed libs,
# and preserve any existing value the user has set.
# and preserve any existing value the user has set. With the Gazebo
# environment from Tools/setup/macos/pixi.toml loaded, its lib dir goes
# first, so a leftover Homebrew Gazebo is never loaded next to it.
if [ "$(uname)" = "Darwin" ]; then
# Load the Gazebo environment from Tools/setup/macos/pixi.toml when the
# venv that normally loads it was not activated, so gz is on PATH.
if [ -z "$CONDA_PREFIX" ] && [ -f "@PX4_SOURCE_DIR@/.venv/bin/px4-gz-env.sh" ]; then
. "@PX4_SOURCE_DIR@/.venv/bin/px4-gz-env.sh"
fi
HOMEBREW_PREFIX=${HOMEBREW_PREFIX:-$(brew --prefix 2>/dev/null)}
if [ -n "$HOMEBREW_PREFIX" ]; then
export DYLD_FALLBACK_LIBRARY_PATH="$HOMEBREW_PREFIX/lib:${DYLD_FALLBACK_LIBRARY_PATH}"
fi
if [ -n "$CONDA_PREFIX" ]; then
export DYLD_FALLBACK_LIBRARY_PATH="$CONDA_PREFIX/lib:${DYLD_FALLBACK_LIBRARY_PATH}"
fi
fi