mirror of
https://github.com/VLSIDA/OpenRAM.git
synced 2026-08-29 17:39:02 +02:00
switch from conda to nix for tooling
This commit is contained in:
@@ -12,6 +12,7 @@ simulations as well.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import numpy as np
|
||||
from openram import debug
|
||||
@@ -406,11 +407,15 @@ class stimuli():
|
||||
spice_stdout = open("{0}spice_stdout.log".format(OPTS.openram_temp), 'w')
|
||||
spice_stderr = open("{0}spice_stderr.log".format(OPTS.openram_temp), 'w')
|
||||
|
||||
# Wrap the command with conda activate & conda deactivate
|
||||
# Run spice in the Nix devShell when Nix-managed tools are enabled.
|
||||
# FIXME: Should use verify/run_script.py here but run_script doesn't return
|
||||
# the return code of the subprocess. File names might also mismatch.
|
||||
from openram import CONDA_HOME
|
||||
cmd = "/bin/bash -c 'source {0}/bin/activate && {1} && conda deactivate'".format(CONDA_HOME, cmd)
|
||||
if OPTS.use_nix:
|
||||
cmd = (
|
||||
"nix --extra-experimental-features 'nix-command flakes' "
|
||||
"develop --command /bin/bash -lc {0}"
|
||||
.format(shlex.quote(cmd))
|
||||
)
|
||||
debug.info(2, cmd)
|
||||
proc = subprocess.run(cmd, stdout=spice_stdout, stderr=spice_stderr, shell=True)
|
||||
|
||||
|
||||
+32
-16
@@ -185,7 +185,7 @@ def init_openram(config_file, is_unit_test=False):
|
||||
|
||||
read_config(config_file, is_unit_test)
|
||||
|
||||
install_conda()
|
||||
install_nix()
|
||||
|
||||
import_tech()
|
||||
|
||||
@@ -206,17 +206,40 @@ def init_openram(config_file, is_unit_test=False):
|
||||
from openram import verify
|
||||
|
||||
|
||||
def install_conda():
|
||||
""" Setup conda for default tools. """
|
||||
def install_nix():
|
||||
"""Initialize Nix-based toolchain dependencies."""
|
||||
|
||||
# Don't setup conda if not used
|
||||
if not OPTS.use_conda or OPTS.is_unit_test:
|
||||
# Don't setup tools during unit tests.
|
||||
if OPTS.is_unit_test:
|
||||
return
|
||||
|
||||
debug.info(1, "Creating conda setup...");
|
||||
if not OPTS.use_nix or OPTS.is_unit_test:
|
||||
return
|
||||
|
||||
from openram import CONDA_INSTALLER
|
||||
subprocess.call(CONDA_INSTALLER)
|
||||
debug.info(1, "Bootstrapping toolchain with Nix...")
|
||||
|
||||
nix_exe = shutil.which("nix")
|
||||
if nix_exe is None:
|
||||
debug.error("Nix is required for automatic tool setup, but 'nix' was not found in PATH.", -1)
|
||||
|
||||
repo_root = os.path.abspath(os.path.join(OPENRAM_HOME, ".."))
|
||||
flake_file = os.path.join(repo_root, "flake.nix")
|
||||
if not os.path.exists(flake_file):
|
||||
debug.error("Expected Nix flake at {} for tool setup.".format(flake_file), -1)
|
||||
|
||||
# Trigger materialization/build of the devShell dependencies once.
|
||||
# Environment activation still happens outside OpenRAM via `nix develop`.
|
||||
cmd = [
|
||||
nix_exe,
|
||||
"--extra-experimental-features", "nix-command flakes",
|
||||
"develop",
|
||||
"--command", "true",
|
||||
]
|
||||
result = subprocess.call(cmd, cwd=repo_root)
|
||||
if result != 0:
|
||||
debug.error("Failed to initialize Nix toolchain (nix develop returned {}).".format(result), -1)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def setup_bitcell():
|
||||
@@ -443,14 +466,7 @@ def find_exe(check_exe):
|
||||
Check if the binary exists in any path dir and return the full path.
|
||||
"""
|
||||
|
||||
# Search for conda setup if used
|
||||
if OPTS.use_conda:
|
||||
from openram import CONDA_HOME
|
||||
search_path = "{0}/bin{1}{2}".format(CONDA_HOME,
|
||||
os.pathsep,
|
||||
os.environ["PATH"])
|
||||
else:
|
||||
search_path = os.environ["PATH"]
|
||||
search_path = os.environ["PATH"]
|
||||
|
||||
# Check if the preferred spice option exists in the path
|
||||
for path in search_path.split(os.pathsep):
|
||||
|
||||
+3
-3
@@ -151,9 +151,9 @@ class options(optparse.Values):
|
||||
###################
|
||||
# Top process that was ran (openram, memchar, memfunc)
|
||||
top_process = None
|
||||
# Use conda to install the default tools
|
||||
# (existing tools will be used if disabled)
|
||||
use_conda = True
|
||||
# Use Nix to initialize the default open-source toolchain.
|
||||
# If disabled, OpenRAM uses whatever tools are already in PATH.
|
||||
use_nix = True
|
||||
# Variable to select the variant of spice
|
||||
spice_name = None
|
||||
# The spice executable being used which is derived from the user PATH.
|
||||
|
||||
@@ -29,26 +29,21 @@ def run_script(cell_name, script="lvs"):
|
||||
|
||||
scriptpath = '{0}run_{1}.sh'.format(OPTS.openram_temp, script)
|
||||
|
||||
# Wrap with conda activate & conda deactivate
|
||||
if OPTS.use_conda:
|
||||
from openram import CONDA_HOME
|
||||
with open(scriptpath, "r") as f:
|
||||
script_content = f.readlines()
|
||||
with open(scriptpath, "w") as f:
|
||||
# First line is shebang
|
||||
f.write(script_content[0])
|
||||
# Activate conda using the activate script
|
||||
f.write("source {}/bin/activate\n".format(CONDA_HOME))
|
||||
for line in script_content[1:]:
|
||||
f.write(line)
|
||||
# Deactivate conda at the end
|
||||
f.write("conda deactivate\n")
|
||||
|
||||
debug.info(2, "Starting {}".format(scriptpath))
|
||||
start = time.time()
|
||||
with open(outfile, 'wb') as fo, open(errfile, 'wb') as fe:
|
||||
if OPTS.use_nix:
|
||||
p_cmd = [
|
||||
"nix",
|
||||
"--extra-experimental-features", "nix-command flakes",
|
||||
"develop",
|
||||
"--command",
|
||||
scriptpath,
|
||||
]
|
||||
else:
|
||||
p_cmd = [scriptpath]
|
||||
p = subprocess.Popen(
|
||||
[scriptpath], stdout=fo, stderr=fe, cwd=OPTS.openram_temp)
|
||||
p_cmd, stdout=fo, stderr=fe, cwd=OPTS.openram_temp)
|
||||
|
||||
if echo_cmd_output:
|
||||
tailo = subprocess.Popen([
|
||||
|
||||
Reference in New Issue
Block a user