Re-apply r197076 and r197086; the build was fixed by chapuni in r197114.