Skip to content

Commit 810afd7

Browse files
committed
update build_locally script to avoid python setup.py develop call
1 parent 909ab6d commit 810afd7

File tree

1 file changed

+44
-61
lines changed

1 file changed

+44
-61
lines changed

scripts/build_locally.py

Lines changed: 44 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,72 +33,55 @@ def run(
3333
target_cuda=None,
3434
target_hip=None,
3535
):
36-
build_system = None
36+
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
37+
env = os.environ.copy()
3738

38-
if "linux" in sys.platform:
39-
build_system = "Ninja"
40-
elif sys.platform in ["win32", "cygwin"]:
41-
build_system = "Ninja"
42-
else:
43-
assert False, sys.platform + " not supported"
39+
cmake_args = []
40+
if c_compiler:
41+
cmake_args.append(f"-DCMAKE_C_COMPILER:PATH={c_compiler}")
42+
if cxx_compiler:
43+
cmake_args.append(f"-DCMAKE_CXX_COMPILER:PATH={cxx_compiler}")
44+
45+
cmake_args.append(f"-DCMAKE_BUILD_TYPE={build_type}")
46+
cmake_args.append(
47+
f"-DDPCTL_ENABLE_L0_PROGRAM_CREATION={'ON' if level_zero else 'OFF'}"
48+
)
49+
cmake_args.append(f"-DDPCTL_ENABLE_GLOG={'ON' if use_glog else 'OFF'}")
4450

45-
setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
46-
cmake_args = [
47-
sys.executable,
48-
"setup.py",
49-
"develop",
50-
]
51-
if cmake_executable:
52-
cmake_args += [
53-
"--cmake-executable=" + cmake_executable,
54-
]
55-
cmake_args += [
56-
"--build-type=" + build_type,
57-
"--generator=" + build_system,
58-
"--",
59-
"-DCMAKE_C_COMPILER:PATH=" + c_compiler,
60-
"-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler,
61-
"-DDPCTL_ENABLE_L0_PROGRAM_CREATION=" + ("ON" if level_zero else "OFF"),
62-
"-DDPCTL_ENABLE_GLOG:BOOL=" + ("ON" if use_glog else "OFF"),
63-
]
6451
if verbose:
65-
cmake_args += [
66-
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
67-
]
68-
if cmake_opts:
69-
cmake_args += cmake_opts.split()
70-
if target_cuda is not None:
52+
cmake_args.append("-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
53+
54+
if cmake_executable:
55+
cmake_args.append(f"-DCMAKE_EXECUTABLE:PATH={cmake_executable}")
56+
57+
if target_cuda:
7158
if not target_cuda.strip():
72-
raise ValueError(
73-
"--target-cuda can not be an empty string. "
74-
"Use --target-cuda=<arch> or --target-cuda"
75-
)
76-
if any(opt.startswith("-DDPCTL_TARGET_CUDA=") for opt in cmake_args):
77-
raise ValueError(
78-
"Both --target-cuda and -DDPCTL_TARGET_CUDA in --cmake-opts "
79-
"were specified. Please use only one method "
80-
"to avoid ambiguity"
81-
)
82-
cmake_args += [
83-
f"-DDPCTL_TARGET_CUDA={target_cuda}",
84-
]
85-
if target_hip is not None:
59+
raise ValueError("--target-cuda cannot be empty")
60+
cmake_args.append(f"-DDPCTL_TARGET_CUDA={target_cuda}")
61+
62+
if target_hip:
8663
if not target_hip.strip():
87-
raise ValueError(
88-
"--target-hip requires an architecture (e.g., gfx90a)"
89-
)
90-
if any(opt.startswith("-DDPCTL_TARGET_HIP=") for opt in cmake_args):
91-
raise ValueError(
92-
"Both --target-hip and -DDPCTL_TARGET_HIP in --cmake-opts "
93-
"were specified. Please use only one method "
94-
"to avoid ambiguity"
95-
)
96-
cmake_args += [
97-
f"-DDPCTL_TARGET_HIP={target_hip}",
98-
]
99-
subprocess.check_call(
100-
cmake_args, shell=False, cwd=setup_dir, env=os.environ
101-
)
64+
raise ValueError("--target_hip cannot be empty")
65+
cmake_args.append(f"-DDPCTL_TARGET_HIP={target_hip}")
66+
67+
env["CMAKE_ARGS"] = " ".join(cmake_args)
68+
69+
# build the Cmake extensions in-place
70+
build_cmd = [sys.executable, "setup.py", "build_ext", "--inplace"]
71+
subprocess.check_call(build_cmd, cwd=setup_dir, env=env)
72+
73+
# editable install with pip
74+
cmd = [
75+
sys.executable,
76+
"-m",
77+
"pip",
78+
"install",
79+
"--no-build-isolation",
80+
"--editable",
81+
".",
82+
]
83+
84+
subprocess.check_call(cmd, cwd=setup_dir, env=env)
10285

10386

10487
if __name__ == "__main__":

0 commit comments

Comments
 (0)