-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
112 lines (96 loc) · 3.35 KB
/
setup.py
File metadata and controls
112 lines (96 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2026 Moore Threads
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import logging
import os
import platform
import random
import re
import shutil
import string
import subprocess
import sys
import sysconfig
import multiprocessing
import setuptools
from setuptools.command import build_ext
from setuptools.command import install_scripts
from setuptools.command.egg_info import egg_info as _egg_info
REPO_DIR = os.path.abspath(os.path.dirname(__file__))
TEMP_BUILD_DIR = os.path.join(REPO_DIR,'build')
AXINFRA_BIN_DIR = os.path.join(REPO_DIR,'axinfra','bin')
class CMakeExtension(setuptools.Extension):
"""A Python extension that has been prebuilt by CMake.
We do not want distutils to handle the build process for our extensions, so
so we pass an empty list to the super constructor.
"""
def __init__(self, name):
super().__init__(name, sources=[])
class BuildCMakeExtension(build_ext.build_ext):
"""Uses CMake to build extensions."""
def run(self):
import subprocess
import pathlib
# /root/works/mt_verse/mujoco_warp_musa/dependencies/mujoco-musa
build_temp = pathlib.Path(TEMP_BUILD_DIR)
build_temp.mkdir(parents=True, exist_ok=True)
build_temp_source = pathlib.Path(REPO_DIR) / "axinfra" / "native"
cmake_args = [
"cmake",
str(pathlib.Path(build_temp_source).resolve()), # 源码根目录
"-DUSE_MUSA=ON",
"-B", str(build_temp.resolve()),
]
subprocess.run(cmake_args)
build_args = [
"cmake",
"--build", str(build_temp.resolve()),
"--target", "axinfra",
"--config", "Release",
"--parallel", str(multiprocessing.cpu_count()),
]
subprocess.run(build_args)
print(build_args)
so_src = build_temp / "libaxinfra.so"
so_dst = pathlib.Path(AXINFRA_BIN_DIR) / "libaxinfra.so"
if pathlib.Path(AXINFRA_BIN_DIR).exists() is False:
pathlib.Path(AXINFRA_BIN_DIR).mkdir(parents=True, exist_ok=True)
print(f"Copying {so_src} to {so_dst}")
shutil.copy2(so_src, so_dst)
class InstallScripts(install_scripts.install_scripts):
"""Strips file extension from executable scripts whose names end in `.py`."""
def run(self):
super().run()
pass
class EggInfoWithBuildExt(_egg_info):
def run(self):
self.run_command('build_ext') # 先执行 build_ext
super().run()
setuptools.setup(
long_description="axinfra native extension with musa support",
long_description_content_type='',
# package_data = {
# 'mujoco_warp': ['_src/warp_musa/bin/*.so'],
# },
# include_package_data=True,
cmdclass=dict(
egg_info=EggInfoWithBuildExt,
build_ext=BuildCMakeExtension,
install_scripts=InstallScripts,
),
ext_modules=[
CMakeExtension('axinfra'),
],
scripts=[]
)