Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vs2010backend: Initial MASM language support #14171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 73 additions & 12 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@ def create_basic_project(self, target_name, *,
conftype='Utility',
target_ext=None,
target_platform=None,
gen_manifest=True) -> T.Tuple[ET.Element, ET.Element]:
gen_manifest=True,
masm_type: T.Optional[T.Literal['masm', 'marmasm']] = None) -> T.Tuple[ET.Element, ET.Element]:
root = ET.Element('Project', {'DefaultTargets': "Build",
'ToolsVersion': '4.0',
'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'})
Expand Down Expand Up @@ -656,6 +657,13 @@ def create_basic_project(self, target_name, *,
# "The build tools for v142 (Platform Toolset = 'v142') cannot be found. ... please install v142 build tools."
# This is extremely unhelpful and misleading since the v14x build tools ARE installed.
ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.props')
ext_settings_grp = ET.SubElement(root, 'ImportGroup', Label='ExtensionSettings')
if masm_type:
ET.SubElement(
ext_settings_grp,
'Import',
Project=rf'$(VCTargetsPath)\BuildCustomizations\{masm_type}.props',
)

# This attribute makes sure project names are displayed as expected in solution files even when their project file names differ
pname = ET.SubElement(globalgroup, 'ProjectName')
Expand Down Expand Up @@ -691,7 +699,8 @@ def create_basic_project(self, target_name, *,
if target_ext:
ET.SubElement(direlem, 'TargetExt').text = target_ext

ET.SubElement(direlem, 'EmbedManifest').text = 'false'
# Fix weird mt.exe error
ET.SubElement(direlem, 'EmbedManifest').text = 'true' if masm_type else 'false'
if not gen_manifest:
ET.SubElement(direlem, 'GenerateManifest').text = 'false'

Expand Down Expand Up @@ -774,12 +783,21 @@ def gen_compile_target_vcxproj(self, target: build.CompileTarget, ofname: str, g
platform = self.build_platform
else:
platform = self.platform

masm = None
if 'masm' in target.compilers:
masm = self.get_masm_type(target)

(root, type_config) = self.create_basic_project(target.name,
temp_dir=target.get_id(),
guid=guid,
target_platform=platform,
gen_manifest=self.get_gen_manifest(target))
gen_manifest=self.get_gen_manifest(target),
masm_type=masm)
ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
ext_tgt_grp = ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets')
if masm:
ET.SubElement(ext_tgt_grp, 'Import', Project=rf'$(VCTargetsPath)\BuildCustomizations\{masm}.targets')
target.generated = [self.compile_target_to_generator(target)]
target.sources = []
self.generate_custom_generator_commands(target, root)
Expand All @@ -794,6 +812,8 @@ def lang_from_source_file(cls, src):
return 'c'
if ext in compilers.cpp_suffixes:
return 'cpp'
if ext in compilers.lang_suffixes['masm']:
return 'masm'
raise MesonException(f'Could not guess language from source file {src}.')

def add_pch(self, pch_sources, lang, inc_cl):
Expand Down Expand Up @@ -1595,14 +1615,18 @@ def gen_vcxproj(self, target: build.BuildTarget, ofname: str, guid: str, vslite_
else:
raise MesonException(f'Unknown target type for {target.get_basename()}')

(sources, headers, objects, _languages) = self.split_sources(target.sources)
(sources, headers, objects, languages) = self.split_sources(target.sources)
if target.is_unity:
sources = self.generate_unity_files(target, sources)
if target.for_machine is MachineChoice.BUILD:
platform = self.build_platform
else:
platform = self.platform

masm = None
if 'masm' in languages and 'masm' in target.compilers:
masm = self.get_masm_type(target)

tfilename = os.path.splitext(target.get_filename())

(root, type_config) = self.create_basic_project(tfilename[0],
Expand All @@ -1611,7 +1635,8 @@ def gen_vcxproj(self, target: build.BuildTarget, ofname: str, guid: str, vslite_
conftype=conftype,
target_ext=tfilename[1],
target_platform=platform,
gen_manifest=self.get_gen_manifest(target))
gen_manifest=self.get_gen_manifest(target),
masm_type=masm)

generated_files, custom_target_output_files, generated_files_include_dirs = self.generate_custom_generator_commands(
target, root)
Expand Down Expand Up @@ -1715,25 +1740,35 @@ def path_normalize_add(path, lis):
for s in sources:
relpath = os.path.join(proj_to_build_root, s.rel_to_builddir(self.build_to_src))
if path_normalize_add(relpath, previous_sources):
inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=relpath)
lang = Vs2010Backend.lang_from_source_file(s)
if lang == 'masm' and masm:
inc_cl = ET.SubElement(inc_src, masm.upper(), Include=relpath)
else:
inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=relpath)

if self.gen_lite:
self.add_project_nmake_defs_incs_and_opts(inc_cl, relpath, defs_paths_opts_per_lang_and_buildtype, platform)
else:
lang = Vs2010Backend.lang_from_source_file(s)
self.add_pch(pch_sources, lang, inc_cl)
if lang != 'masm':
self.add_pch(pch_sources, lang, inc_cl)
self.add_additional_options(lang, inc_cl, file_args)
self.add_preprocessor_defines(lang, inc_cl, file_defines)
self.add_include_dirs(lang, inc_cl, file_inc_dirs)
ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + \
self.object_filename_from_source(target, compiler, s)
for s in gen_src:
if path_normalize_add(s, previous_sources):
inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=s)
lang = Vs2010Backend.lang_from_source_file(s)
if lang == 'masm' and masm:
inc_cl = ET.SubElement(inc_src, masm.upper(), Include=s)
else:
inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=s)

if self.gen_lite:
self.add_project_nmake_defs_incs_and_opts(inc_cl, s, defs_paths_opts_per_lang_and_buildtype, platform)
else:
lang = Vs2010Backend.lang_from_source_file(s)
self.add_pch(pch_sources, lang, inc_cl)
if lang != 'masm':
self.add_pch(pch_sources, lang, inc_cl)
self.add_additional_options(lang, inc_cl, file_args)
self.add_preprocessor_defines(lang, inc_cl, file_defines)
self.add_include_dirs(lang, inc_cl, file_inc_dirs)
Expand Down Expand Up @@ -1782,6 +1817,9 @@ def path_normalize_add(path, lis):
ET.SubElement(inc_objs, 'Object', Include=s)

ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
ext_tgt_grp = ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets')
if masm:
ET.SubElement(ext_tgt_grp, 'Import', Project=rf'$(VCTargetsPath)\BuildCustomizations\{masm}.targets')
self.add_regen_dependency(root)
if not self.gen_lite:
# Injecting further target dependencies into this vcxproj implies and forces a Visual Studio BUILD dependency,
Expand Down Expand Up @@ -2092,7 +2130,7 @@ def generate_lang_standard_info(self, file_args: T.Dict[str, CompilerArgs], clco
pass

# Returns if a target generates a manifest or not.
def get_gen_manifest(self, target):
def get_gen_manifest(self, target: T.Optional[build.BuildTarget]):
if not isinstance(target, build.BuildTarget):
return True

Expand All @@ -2112,3 +2150,26 @@ def get_gen_manifest(self, target):
if arg == '/MANIFEST' or arg.startswith('/MANIFEST:'):
break
return True

# FIXME: add a way to distinguish between arm64ec+marmasm (written in ARM assembly)
# and arm64ec+masm (written in x64 assembly).
#
# For now, assume it's the native ones. (same behavior as ninja backend)
def get_masm_type(self, target: build.BuildTarget):
if not isinstance(target, build.BuildTarget):
return None

if 'masm' not in target.compilers:
return None

if target.for_machine == MachineChoice.BUILD:
platform = self.build_platform
elif target.for_machine == MachineChoice.HOST:
platform = self.platform
else:
return None

if platform in {'ARM', 'arm64', 'arm64ec'}:
return 'marmasm'
else:
return 'masm'
Loading