Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Mar 12, 2024
1 parent 5c71631 commit 83fae31
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
3 changes: 3 additions & 0 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ def determine_linker_and_stdlib_args(self, target: build.BuildTarget) -> T.Tuple
If we're building a static library, there is only one static linker.
Otherwise, we query the target for the dynamic linker.
'''
print("determine_linker_and_stdlib_args()")
print("\ttarget:", target)
print("\ttarget.for_machine:", target.for_machine)
if isinstance(target, build.StaticLibrary):
return self.build.static_linker[target.for_machine], []
l, stdlib_args = target.get_clink_dynamic_linker_and_stdlibs()
Expand Down
9 changes: 9 additions & 0 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ def create_target_linker_introspection(self, target: build.Target, linker: T.Uni
tgt[lnk_hash] = lnk_block

def generate_target(self, target):
print("generate_target():", target)
print("\tfor_machine:", target.for_machine)
try:
if isinstance(target, build.BuildTarget):
os.makedirs(self.get_target_private_dir_abs(target))
Expand Down Expand Up @@ -1040,6 +1042,9 @@ def generate_target(self, target):
final_obj_list = self.generate_prelink(target, obj_list)
else:
final_obj_list = obj_list
print("calling generate_link()")
print("\tlinker:", linker)
print("\tlinker.for_machine:", linker.for_machine)
elem = self.generate_link(target, outname, final_obj_list, linker, pch_objects, stdlib_args=stdlib_args)
self.generate_dependency_scan_target(target, compiled_sources, source2object, generated_source_files, fortran_order_deps)
self.add_build(elem)
Expand Down Expand Up @@ -3323,6 +3328,10 @@ def guess_external_link_dependencies(self, linker, target, commands, internal):
try:
static_patterns = linker.get_library_naming(self.environment, LibType.STATIC, strict=True)
shared_patterns = linker.get_library_naming(self.environment, LibType.SHARED, strict=True)
print("calling linker.get_library_dirs()")
print("\tlinker:", linker)
print("\ttarget:", target)
print("\ttarget.for_machine:", target.for_machine)
search_dirs = tuple(search_dirs) + tuple(linker.get_library_dirs(self.environment))
for libname in libs:
# be conservative and record most likely shared and static resolution, because we don't know exactly
Expand Down
19 changes: 19 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def merge(self, other: Build) -> None:
self.__dict__[k] = v

if is_native_clone:
self.environment.coredata.merge_from_native_cross(other.environment.coredata)
print("TODOOOO")
pass

Expand Down Expand Up @@ -1647,17 +1648,30 @@ def get_clink_dynamic_linker_and_stdlibs(self) -> T.Tuple['Compiler', T.List[str
'''
# If the user set the link_language, just return that.
if self.link_language:
print("get_clink_dynamic_linker_and_stdlibs(): A")
comp = self.all_compilers[self.link_language]
return comp, comp.language_stdlib_only_link_flags(self.environment)

# Since dependencies could come from subprojects, they could have
# languages we don't have in self.all_compilers. Use the global list of
# all compilers here.
all_compilers = self.environment.coredata.compilers[self.for_machine]
print("get_clink_dynamic_linker_and_stdlibs(): B")
print("\tself.for_machine:", self.for_machine)

# Languages used by dependencies
dep_langs = self.get_langs_used_by_deps()

import pprint
print("\tself.compilers:")
print("\tvvv")
pprint.pp(self.compilers)
print("\t^^^")
print("\tall_compilers:")
print("\tvvv")
pprint.pp(all_compilers)
print("\t^^^")

# Pick a compiler based on the language priority-order
for l in clink_langs:
if l in self.compilers or l in dep_langs:
Expand All @@ -1668,11 +1682,16 @@ def get_clink_dynamic_linker_and_stdlibs(self) -> T.Tuple['Compiler', T.List[str
f'Could not get a dynamic linker for build target {self.name!r}. '
f'Requires a linker for language "{l}", but that is not '
'a project language.')
print("\textracted linker:")
print(linker)
print("\twhich has for_machine:", linker.for_machine)
stdlib_args: T.List[str] = self.get_used_stdlib_args(linker.language)
# Type of var 'linker' is Compiler.
# Pretty hard to fix because the return value is passed everywhere
return linker, stdlib_args

print("get_clink_dynamic_linker_and_stdlibs(): C")

# None of our compilers can do clink, this happens for example if the
# target only has ASM sources. Pick the first capable compiler.
for l in clink_langs:
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ def _get_basic_compiler_args(self, env: 'Environment', mode: CompileCheckMode) -
pass

# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env
print("calling env.coredata.get_external_args()")
print("\tself:", self)
print("\tfor_machine:", self.for_machine)
print("\tself.language:", self.language)
sys_args = env.coredata.get_external_args(self.for_machine, self.language)
if isinstance(sys_args, str):
sys_args = [sys_args]
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ def copy_to_native(self) -> CoreData:

return other

def merge_from_native_cross(self, other: CoreData) -> None:
compiler_opts = {k.as_build(): v for k, v in other.options.items() if k.type is OptionType.COMPILER}
self.options.update(compiler_opts)

@staticmethod
def __load_config_files(options: argparse.Namespace, scratch_dir: str, ftype: str) -> T.List[str]:
# Need to try and make the passed filenames absolute because when the
Expand Down
15 changes: 7 additions & 8 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,8 @@ def _do_subproject_meson(self, subp_name: str, subp_id: str, subdir: str,
mlog.log('Generated Meson AST:', meson_filename)
mlog.cmd_ci_include(meson_filename)

is_native_cross = native and self.coredata.is_cross_build() and not self.coredata.is_native_clone
if is_native_cross:
is_native_cross_boundary = native and self.coredata.is_cross_build() and not self.coredata.is_native_clone
if is_native_cross_boundary:
new_build = self.build.copy_to_native()
default_options = {k.as_build(): v for k, v in default_options.items()}
new_subprojects = {k: v for k, v in self.subprojects.items() if k[1] is MachineChoice.BUILD}
Expand Down Expand Up @@ -1033,7 +1033,7 @@ def _do_subproject_meson(self, subp_name: str, subp_id: str, subdir: str,
try:
subi.run()
finally:
if is_native_cross:
if is_native_cross_boundary:
self._merge_native_cross_subprojects(new_subprojects, prev_subproject_ids)
subi_warnings = mlog.get_warning_count()
mlog.log('Subproject', mlog.bold(subp_name), 'finished.')
Expand Down Expand Up @@ -1375,15 +1375,14 @@ def func_add_languages(self, node: mparser.FunctionNode, args: T.Tuple[T.List[st
for lang in sorted(langs, key=compilers.sort_clink):
mlog.log('Compiler for language', mlog.bold(lang), 'skipped: feature', mlog.bold(feature), 'disabled')
return False
if self.coredata.is_native_clone:
print("add_langauges() XXX")
return self.add_languages(langs, required, MachineChoice.BUILD)
if native is not None:
print("add_langauges() A")
print("using machine:", self.machine_from_native_kwarg(kwargs))
for_machine = self.machine_from_native_kwarg(kwargs)
success = self.add_languages(langs, required, for_machine)
if self.coredata.is_native_clone:
other_machine = MachineChoice.BUILD if for_machine is MachineChoice.HOST else MachineChoice.HOST
success &= self.add_languages(langs, required, other_machine)
return success
return self.add_languages(langs, required, for_machine)
else:
print("add_langauges() B")
# absent 'native' means 'both' for backwards compatibility
Expand Down

0 comments on commit 83fae31

Please sign in to comment.