Build assembly files with AMBuild. (#481)

* Remove prebuilt nasm-generated object files from the tree, and use AMBuild to compile them.

* Add commands in VS project to build the object files

* Rename elf to elf32 for consistency
This commit is contained in:
David Anderson 2018-08-26 11:28:25 -07:00 committed by Vincent Herbet
parent 9bcabfeb1f
commit 46d1ef68bd
21 changed files with 127 additions and 32 deletions

2
.gitignore vendored
View File

@ -84,3 +84,5 @@ Thumbs.db
# AMXX plugin build related files
plugins/compile.dat
plugins/compiled/
build_deps/

View File

@ -8,6 +8,7 @@ addons:
- linux-libc-dev
- gcc-multilib
- g++-multilib
- nasm
sources:
- llvm-toolchain-precise-3.7
- ubuntu-toolchain-r-test

View File

@ -20,6 +20,7 @@ class AMXXConfig(object):
self.utf8rewind = None
self.csx_app = None
self.stdcxx_path = None
self.nasm_path = None
def use_auto_versioning(self):
if builder.backend != 'amb2':
@ -105,6 +106,31 @@ class AMXXConfig(object):
if not self.mysql_path:
raise Exception('Could not find MySQL! Try passing --mysql to configure.py.')
def detectNASM(self):
import subprocess
nasm_paths = [
getattr(builder.options, 'nasm_path', 'nasm'),
]
if builder.target_platform == 'windows':
nasm_paths += [os.path.join(
builder.sourcePath,
'build_deps',
'nasm',
'nasm.exe')
]
for nasm_path in nasm_paths:
try:
subprocess.check_output([nasm_path, '-v'])
self.nasm_path = nasm_path
break
except:
pass
if self.nasm_path is None:
raise Exception('Could not find a suitable path for nasm')
# Returns list of lines of output from the compiler
@staticmethod
def invokeCompiler(args):
@ -369,11 +395,42 @@ class AMXXConfig(object):
binary = context.compiler.Program(name)
return self.AddVersioning(binary)
def AddAssembly(self, context, binary, input_file, output_file, includes=[], extra_argv=[]):
if builder.target_platform == 'windows':
obj_type = 'win32'
elif builder.target_platform == 'linux':
obj_type = 'elf32'
elif builder.target_platform == 'mac':
obj_type = 'macho32'
input_path = os.path.join(context.currentSourcePath, input_file)
output_path = output_file
argv = [
self.nasm_path,
'-I{0}{1}'.format(context.currentSourcePath, os.sep),
input_path,
'-f', obj_type,
'-o', output_path,
] + extra_argv
extra_includes = []
for include_file in includes:
extra_includes.append(os.path.join(context.currentSourcePath, include_file))
cmd_node, output_nodes = context.AddCommand(
inputs = [input_path] + extra_includes,
argv = argv,
outputs = [output_path])
binary.compiler.linkflags += [output_nodes[0]]
AMXX = AMXXConfig()
AMXX.detectProductVersion()
AMXX.detectMetamod()
AMXX.detectHlsdk()
AMXX.detectMysql()
AMXX.detectNASM()
AMXX.configure()
if AMXX.use_auto_versioning():

View File

@ -9,36 +9,25 @@ binary.compiler.defines += [
'HAVE_STDINT_H',
]
AMXX.AddAssembly(builder, binary, 'helpers-x86.asm', 'helpers-asm.obj')
AMXX.AddAssembly(builder, binary, 'natives-x86.asm', 'natives-asm.obj')
AMXX.AddAssembly(builder, binary, 'amxexecn.asm', 'amxexecn-asm.obj',
includes=['amxdefn.asm'])
AMXX.AddAssembly(builder, binary, 'amxjitsn.asm', 'amxjitsn-asm.obj',
includes=['amxdefn.asm'],
# Opcode sizes must be maximum width for patching to work.
extra_argv=['-O0'])
if builder.target_platform == 'mac':
jit_objects = [
binary.Dep('JIT/amxexecn-darwin.o'),
binary.Dep('JIT/amxjitsn-darwin.o'),
binary.Dep('JIT/natives-darwin-x86.o'),
binary.Dep('JIT/helpers-darwin-x86.o'),
]
binary.compiler.postlink += [
'-Wl,-read_only_relocs,suppress'
]
elif builder.target_platform == 'linux':
jit_objects = [
binary.Dep('JIT/amxexecn.o'),
binary.Dep('JIT/amxjitsn.o'),
binary.Dep('JIT/natives-x86.o'),
binary.Dep('JIT/helpers-x86.o'),
]
elif builder.target_platform == 'windows':
jit_objects = [
binary.Dep('JIT/amxexecn.obj'),
binary.Dep('JIT/amxjitsn.obj'),
binary.Dep('JIT/helpers-x86.obj'),
binary.Dep('JIT/natives-x86.obj'),
]
binary.compiler.linkflags += [
'/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1',
'/SECTION:.data,RW',
]
binary.compiler.linkflags += jit_objects
binary.compiler.linkflags += [AMXX.zlib.binary, AMXX.hashing.binary, AMXX.utf8rewind.binary]
binary.sources = [

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -96,6 +96,14 @@
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<SpecifySectionAttributes>.data,RW</SpecifySectionAttributes>
</Link>
<PreBuildEvent>
<Command>cd ..
md -p JIT 2&gt;NUL
%NASM_PATH%nasm.exe -f win32 helpers-x86.asm -o JIT/helpers-x86.obj
%NASM_PATH%nasm.exe -f win32 natives-x86.asm -o JIT/natives-x86.obj
%NASM_PATH%nasm.exe -f win32 amxexecn.asm -o JIT/amxexecn.obj
%NASM_PATH%nasm.exe -O0 -f win32 amxjitsn.asm -o JIT/amxjitsn.obj</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='JITRelease|Win32'">
<Midl>
@ -148,6 +156,14 @@
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<SpecifySectionAttributes>.data,RW</SpecifySectionAttributes>
</Link>
<PreBuildEvent>
<Command>cd ..
md -p JIT 2&gt;NUL
%NASM_PATH%nasm.exe -f win32 helpers-x86.asm -o JIT/helpers-x86.obj
%NASM_PATH%nasm.exe -f win32 natives-x86.asm -o JIT/natives-x86.obj
%NASM_PATH%nasm.exe -f win32 amxexecn.asm -o JIT/amxexecn.obj
%NASM_PATH%nasm.exe -O0 -f win32 amxjitsn.asm -o JIT/amxjitsn.obj</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\public\memtools\CDetour\asm\asm.c" />

View File

@ -3,6 +3,11 @@ clone_folder: c:\projects\amxmodx
install:
- git submodule update --init --recursive
- 'c:'
- mkdir c:\nasm
- set PATH=c:\nasm\nasm-2.13.03;%PATH%
- curl -o "c:\nasm\nasm.zip" http://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win32/nasm-2.13.03-win32.zip
- chdir c:\nasm
- 7z x nasm.zip
- chdir c:\projects
- git clone https://github.com/alliedmodders/ambuild
- git clone https://github.com/alliedmodders/metamod-hl1
@ -22,5 +27,5 @@ build_script:
- '"%VS120COMNTOOLS%\vsvars32.bat"'
- mkdir build
- cd build
- c:\python27\python ../configure.py --enable-optimize
- c:\python27\python ../configure.py --enable-optimize --nasm="C:\nasm\nasm-2.13.03\nasm.exe"
- c:\python27\scripts\ambuild

View File

@ -30,4 +30,6 @@ run.options.add_option('--mysql', type='string', dest='mysql_path', default='',
help='Path to MySQL')
run.options.add_option('--disable-auto-versioning', action='store_true', dest='disable_auto_versioning',
default=False, help='Disable the auto versioning script')
run.options.add_option('--nasm', type='string', dest='nasm_path',
default='nasm', help='Path to NASM')
run.Configure()

View File

@ -5,6 +5,22 @@ if [ ! -d "amxmodx" ]; then
git clone --recursive https://github.com/alliedmodders/amxmodx.git
fi
if [ ! -d "amxmodx/build_deps" ]; then
mkdir amxmodx/build_deps
fi
download_archive ()
{
if [ `command -v wget` ]; then
wget "$url" -O "$dest"
elif [ `command -v curl` ]; then
curl -o $dest $url
else
echo "Failed to locate wget or curl. Please install one of these programs."
exit 1
fi
}
if [ "$1" != "--no-mysql" ]; then
ismac=0
iswin=0
@ -34,14 +50,9 @@ if [ "$1" != "--no-mysql" ]; then
fi
if [ ! -d "mysql-5.5" ]; then
if [ `command -v wget` ]; then
wget $mysqlurl -O mysql.$archive_ext
elif [ `command -v curl` ]; then
curl -o mysql.$archive_ext $mysqlurl
else
echo "Failed to locate wget or curl. Install one of these programs to download MySQL."
exit 1
fi
url=$mysqlurl
dest=mysql.$archive_ext
download_archive
$decomp mysql.$archive_ext
mv $mysqlver mysql-5.5
rm mysql.$archive_ext
@ -95,3 +106,15 @@ if [ $? -eq 1 ]; then
python setup.py install --user
fi
fi
if [ $iswin -eq 1 ]; then
if [ ! -d "amxmodx/build_deps/nasm-2.13.03" ]; then
url=http://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win32/nasm-2.13.03-win32.zip
dest=amxmodx/build_deps/nasm-2.13.03-win32.zip
download_archive
cd amxmodx/build_deps
unzip nasm-2.13.03-win32.zip
rm nasm-2.13.03-win32.zip
mv nasm-2.13.03 nasm
fi
fi