@@ -313,17 +313,17 @@ def _python_impl(module_ctx):
313313 platforms = platforms ,
314314 ** kwargs
315315 )
316- print ("{} registered platforms: {}" .format (toolchain_info .name , tc_created_platforms ))
317316 loaded_platforms [full_python_version ] = tc_created_platforms
317+ print ("{} registered platforms: {}" .format (toolchain_info .name , tc_created_platforms ))
318318 for loaded in tc_created_platforms :
319319 info = platforms [loaded ]
320320 if info .os_name == host_os and info .arch == host_cpu :
321321 host_compatible .append (struct (
322- ## repo_prefix = toolchain_info.name,
322+ repo_prefix = toolchain_info .name ,
323323 repo_name = toolchain_info .name + "_" + loaded ,
324324 full_python_version = full_python_version ,
325- ## base_version = toolchain_info.python_version,
326- ## platform_name = loaded,
325+ base_version = toolchain_info .python_version ,
326+ platform_name = loaded ,
327327 ##platform_info = info,
328328 ))
329329 print ("create host for:" , toolchain_info .name , toolchain_info .python_version )
@@ -368,6 +368,12 @@ def _python_impl(module_ctx):
368368 "best match" means:
369369 * for major.minor, the highest version <= the minor_mapping bound
370370 * for major.minor.patch: whatever is available, but maybe nothing.
371+
372+ Or, maybe just detect what needs more advanced matching.
373+ So if python_register_toolchains(X) is able to find a match for host,
374+ that's fine.
375+ If it can't, then we use more advanced matching.
376+
371377 """
372378 minor_mapping = py .config .minor_mapping
373379
@@ -417,7 +423,20 @@ def _python_impl(module_ctx):
417423 for host_needed_base_name , host_needed in host_repos_to_create .items ():
418424 print ("find backend for:" , host_needed_base_name , "v:" , host_needed .version )
419425 needed_version_str = host_needed .version
420- backing_repo_name = None
426+ backing_repo_names = None
427+
428+ def candidate_key (e ):
429+ pref = 0
430+ if e .platform_name .endswith ("-freethreaded" ):
431+ pref = - 1
432+ elif e .platform_name .endswith ("-musl" ):
433+ pref = - 2
434+
435+ return (
436+ 0 if e .repo_prefix == host_needed_base_name else - 1 ,
437+ version_tuple (e .full_python_version ),
438+ pref ,
439+ )
421440
422441 # Major.Minor case: look for a minor <= the minor_mapping bound
423442 # that is compatible with our host
@@ -431,30 +450,43 @@ def _python_impl(module_ctx):
431450 #print("add candidate:", entry)
432451 candidates .append (entry )
433452
434- def keyer (e ):
435- return (
436- version_tuple (e .full_python_version ),
437- )
438-
439453 candidates = sorted (
440454 candidates ,
441455 reverse = True ,
442- key = lambda e : ( version_tuple ( e . full_python_version ), e . repo_name ) ,
456+ key = candidate_key ,
443457 )
444458 print ("sorted candidates:" )
445459 for x in candidates :
446460 print (" " , x )
447- if candidates :
448- backing_repo_name = candidates [0 ].repo_name
461+ backing_repo_names = [c .repo_name for c in candidates ]
449462 else :
450- fail ("not implemented: fv" , needed_version_str )
463+ candidates = []
464+ for entry in host_compatible :
465+ if entry .full_python_version == needed_version_str :
466+ candidates .append (entry )
467+ candidates = sorted (candidates , reverse = True , key = candidate_key )
468+ backing_repo_names = [c .repo_name for c in candidates ]
469+ #fail("not implemented: fv", needed_version_str)
451470
452- if not backing_repo_name :
471+ if not backing_repo_names and host_needed . version not in ( "3.13.3" ,) :
453472 fail ("no host-compatible repo found" , host_needed )
454- print ("{} using {}" .format (host_needed_base_name , backing_repo_name ))
473+
474+ # Argh. Old impl:
475+ # create python_3_10_linux
476+ # create python_3_10_host using python_3_10_linux
477+ # new impl:
478+ # create python_3_10_linux
479+ # create python_3_10_host using python_3_10_X_linux
480+ # Thing to do is give preference such that e.g.
481+ # python_3_10 prefers python_3_10_linux_x86 over python_3_10_9_linux_x86
482+ backing_repo_names = [
483+ x .removeprefix (host_needed_base_name + "_" )
484+ for x in backing_repo_names
485+ ]
486+ print ("{} using {}" .format (host_needed_base_name , backing_repo_names ))
455487 host_toolchain (
456488 name = host_needed_base_name + "_host" ,
457- backing_repo_name = backing_repo_name ,
489+ backing_repo_names = backing_repo_names ,
458490 )
459491
460492 # Now major_minor_lte maps major_minor to a list of descending full
0 commit comments