in procgen/builder.py [0:0]
def build(package=False, debug=False):
"""
Build the requested environment in a process-safe manner and only once per process.
"""
build_dir = os.path.join(SCRIPT_DIR, ".build")
os.makedirs(build_dir, exist_ok=True)
build_type = "relwithdebinfo"
if debug:
build_type = "debug"
with chdir(build_dir), global_build_lock:
# check if we have built yet in this process
if build_type not in global_builds:
if package:
# avoid the filelock dependency when building from setup.py
lock_ctx = nullcontext()
else:
# prevent multiple processes from trying to build at the same time
import filelock
lock_ctx = filelock.FileLock(".build-lock")
with lock_ctx:
sys.stdout.write("building procgen...")
sys.stdout.flush()
try:
os.makedirs(build_type, exist_ok=True)
with chdir(build_type):
_attempt_configure(build_type, package)
except RunFailure:
# cmake can get into a weird state, so nuke the build directory and retry once
sys.stdout.write("retrying configure due to failure...")
sys.stdout.flush()
shutil.rmtree(build_type)
os.makedirs(build_type, exist_ok=True)
with chdir(build_type):
_attempt_configure(build_type, package)
if "MAKEFLAGS" not in os.environ:
os.environ["MAKEFLAGS"] = f"-j{mp.cpu_count()}"
with chdir(build_type):
build_cmd = ["cmake", "--build", ".", "--config", build_type]
check(run(build_cmd), verbose=package)
print("done")
global_builds.add(build_type)
lib_dir = os.path.join(build_dir, build_type)
if platform.system() == "Windows":
# the built library is in a different location on windows
lib_dir = os.path.join(lib_dir, build_type)
return lib_dir