Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1172 commits
Select commit Hold shift + click to select a range
15e17a3
Inline _compile_module_args
aherrmann Jun 12, 2024
0e2a50c
Remove duplicate compile_cmd object
aherrmann Jun 12, 2024
b0aecae
Inline compile_args_for_file
aherrmann Jun 12, 2024
b25cdd7
Remove indirection for srcs
aherrmann Jun 12, 2024
30b4b58
Remove CompileArgsInfo
aherrmann Jun 12, 2024
de6c517
Remove intermediate CompileResultInfo
aherrmann Jun 12, 2024
52c60ff
Remove unused field type variant
aherrmann Jun 12, 2024
8361d3a
inline packages_info.exposed_package_modules
aherrmann Jun 12, 2024
1d5a626
Remove redundant branch
aherrmann Jun 12, 2024
7d6b2ce
TODO note
aherrmann Jun 12, 2024
a4744d6
Remove redundant intermediate variable
aherrmann Jun 12, 2024
15566d8
remove inline markers
aherrmann Jun 12, 2024
2c9f8b7
remove redundant modname
aherrmann Jun 12, 2024
4498960
Remove unused variable
aherrmann Jun 12, 2024
9b0089d
Merge pull request #13 from MercuryTechnologies/refactor
aherrmann Jun 13, 2024
b816494
Remove duplicate variable
avdv Jun 11, 2024
1d02ff6
Remove superfluous `-package-db` flags passed to ghc
avdv Jun 11, 2024
da813a3
Keep track of the path for each haskell package db
avdv Jun 11, 2024
c5f99d7
Add `--bin-path` argument to `ghc_wrapper.py` and `generate_target_me…
avdv Jun 11, 2024
912c4f6
Pass `--bin-path` flag for each toolchain library dependency
avdv Jun 11, 2024
516bfdf
Allow to declare dependencies for haskell sources manually
avdv Jun 13, 2024
e9ef00f
Warn about non-haskell source files in `srcs`, advice to use `srcs_deps`
avdv Jun 13, 2024
b968190
Merge pull request #12 from MercuryTechnologies/cb/haskell-bin-tools
avdv Jun 14, 2024
307e26e
inline get_packages_info for _compile_module
aherrmann Jun 12, 2024
bce4d37
Inline bool constants
aherrmann Jun 12, 2024
d78eba6
Resolve branches under bool constants
aherrmann Jun 12, 2024
01556eb
Remove redundant if
aherrmann Jun 12, 2024
ee81195
Remove duplicate variables
aherrmann Jun 12, 2024
eb34675
Inline pkg_name
aherrmann Jun 12, 2024
0421ee6
Inline packages_info.packagedb_args
aherrmann Jun 12, 2024
be0af5f
Remove unused exposed_package_libs
aherrmann Jun 12, 2024
e6079b8
inline exposed_package_modules
aherrmann Jun 12, 2024
6cab823
inline exposed_package_dbs
aherrmann Jun 12, 2024
537b49e
Remove unused PackagesInfo
aherrmann Jun 12, 2024
16cb90b
get_packages_info remove unused package_deps
aherrmann Jun 12, 2024
b31371d
get_packages_info consistently use no empty lib
aherrmann Jun 12, 2024
67e57ac
Revert "get_packages_info consistently use no empty lib"
aherrmann Jun 12, 2024
f3c4301
Remove unused exposed_package_modules
aherrmann Jun 12, 2024
6781f87
Remove unused exposed_package_imports
aherrmann Jun 12, 2024
a765e7a
Remove unused exposed_package_objects
aherrmann Jun 12, 2024
39e3140
Remove outdated comment
aherrmann Jun 12, 2024
1369e33
Remove unused exposed_package_dbs
aherrmann Jun 12, 2024
19186dc
reorder binding
aherrmann Jun 13, 2024
84f5165
Remove unused binding
aherrmann Jun 13, 2024
7152967
Reorder bindings
aherrmann Jun 13, 2024
863391e
Remove unused binding
aherrmann Jun 13, 2024
115d0f8
Reorder bindings
aherrmann Jun 13, 2024
1b643c5
Remove inlining markers
aherrmann Jun 13, 2024
b6f92c5
Iterate over module's package deps
aherrmann Jun 13, 2024
a99fdb0
remove outdated comment
aherrmann Jun 13, 2024
a8d23c1
binding order
aherrmann Jun 13, 2024
ceb8404
Fix bin_paths error due to rebase
aherrmann Jun 14, 2024
379cb1b
Merge pull request #14 from MercuryTechnologies/refactor-2
aherrmann Jun 14, 2024
abf52dd
Pass only the current module to _compile_module
aherrmann Jun 13, 2024
8df1495
bubble up non module specific args
aherrmann Jun 13, 2024
0aae557
bubble cpp flags
aherrmann Jun 13, 2024
bfdbb9f
bubble up non-module specific extra source files
aherrmann Jun 13, 2024
550eeed
Factor out common command line arguments
aherrmann Jun 13, 2024
108fee3
Move common compile flags
aherrmann Jun 14, 2024
4b73cef
Factor out direct_deps_info
aherrmann Jun 14, 2024
09ad9ff
Factor out direct_deps_by_name
aherrmann Jun 14, 2024
26bf616
pull down per module analysis
aherrmann Jun 14, 2024
c19828e
Factor out packagedb tagging
aherrmann Jun 14, 2024
f013868
Factor out common package-db flags
aherrmann Jun 17, 2024
d5e7dc0
remove unused arguments
aherrmann Jun 17, 2024
2f5ab29
Merge pull request #15 from MercuryTechnologies/refactor-3
aherrmann Jun 17, 2024
dc554a4
Avoid recompilation for binaries from haskell packages
avdv Jun 17, 2024
ec8f4f1
Remove `path` projection for HaskellPackageDbTSet
avdv Jun 17, 2024
fc95052
Merge pull request #16 from MercuryTechnologies/cb/avoid-recompilatio…
avdv Jun 18, 2024
a598146
TMP: capture raw GHC -M output
aherrmann Jun 19, 2024
e956579
The -opt-json GHC flag was removed
aherrmann Jun 19, 2024
1bae159
update TH detection
aherrmann Jun 19, 2024
87d9a51
calculate module mapping
aherrmann Jun 19, 2024
0704a08
determine module graph
aherrmann Jun 19, 2024
c7013a4
determine package and toolchain dependencies
aherrmann Jun 19, 2024
f4d21c3
resolve package-ids of package dependencies
aherrmann Jun 19, 2024
8b7aa6e
obtain base package id from catalog
aherrmann Jun 19, 2024
31455ef
Remove unused code
aherrmann Jun 19, 2024
0bd7c79
Remove raw ghc_depends output
aherrmann Jun 19, 2024
e22bb61
Remove unused import-dirs trie
aherrmann Jun 19, 2024
af8ba19
Merge pull request #17 from MercuryTechnologies/new-json-patch
aherrmann Jun 28, 2024
f967596
Remove toolchain library catalog
aherrmann Jun 28, 2024
7a79c89
Merge pull request #19 from MercuryTechnologies/avoid-library-catalog
aherrmann Jun 28, 2024
e3e2571
Use ArgLike for `db` in `HaskellPackage`
avdv Jun 27, 2024
878263b
Remove `package_db` from `HaskellPackagesInfo`
avdv Jul 1, 2024
12d0d58
Merge pull request #18 from MercuryTechnologies/cb/make-package-db-nix
avdv Jul 2, 2024
0c629b8
remove objects from TH compile actions
aherrmann Jul 16, 2024
1cb9b2d
Set -fprefer-byte-code for TH splices
aherrmann Jul 16, 2024
fbbc43b
Remove .dyn_o to .o symlinks
aherrmann Jul 16, 2024
8f34513
Remove module package dependency tracking
aherrmann Jul 16, 2024
f8c0a3b
Remove module toolchain lib dependency tracking
aherrmann Jul 16, 2024
e75357a
Remove module objects reduction
aherrmann Jul 16, 2024
d618d7b
No more md_json dependency per module
wavewave Jul 24, 2024
94d50d4
try to fix -i(dir)
wavewave Jul 24, 2024
20379ed
Merge pull request #20 from MercuryTechnologies/bytecode-linking
aherrmann Aug 5, 2024
6856536
Merge pull request #21 from MercuryTechnologies/wavewave/no-more-md-j…
wavewave Aug 8, 2024
596683f
Extract boot module dependencies
aherrmann Aug 14, 2024
2095e58
Generate module objects for boot files
aherrmann Aug 14, 2024
8a7473e
Extend module dep graph by boot deps
aherrmann Aug 14, 2024
055378c
Copy package deps onto boot module
aherrmann Aug 14, 2024
fa1a20d
Use md_file for `-outputdir`
aherrmann Aug 14, 2024
d67535e
Skip stubdir output for boot modules
aherrmann Aug 14, 2024
e17d3f2
Skip .o-boot files when linking
aherrmann Aug 14, 2024
c143bca
Simplify boot module dep graph integration
aherrmann Aug 14, 2024
f34c43b
Calculate reverse boot file dep graph
aherrmann Aug 14, 2024
c5457ce
Add boot module dependencies
aherrmann Aug 14, 2024
9a176da
Revert "try to fix -i(dir)"
aherrmann Aug 14, 2024
0d82d97
Revert "No more md_json dependency per module"
aherrmann Aug 14, 2024
6a18a8d
Set ignore_artifacts on md_file input
aherrmann Aug 14, 2024
fe24a6d
Avoid non-haskell source warning for boot files
aherrmann Aug 14, 2024
ad8e597
Merge pull request #22 from MercuryTechnologies/boot-file
aherrmann Aug 15, 2024
08bea3e
Do not require haskell toolchain packages
avdv Aug 14, 2024
e664b5c
Handle `main` attribute for haskell binaries
avdv Aug 14, 2024
a525b55
Do not use `-outputdir`
avdv Aug 14, 2024
45b724f
Add `src_strip_prefix` attribute
avdv Aug 14, 2024
1e204c1
Add `src_strip_prefix` to `haskell_library` rule
avdv Aug 14, 2024
c1964b3
Append `src_strip_prefix` to module prefix_dir
avdv Aug 14, 2024
400e624
Strip src prefix from exposed-modules in package config
avdv Aug 14, 2024
f8530ec
Append src prefix to import-dirs of package conf
avdv Aug 14, 2024
ab08a62
Do not append `src_prefix` to `library-dirs` in package conf
avdv Aug 15, 2024
3365ba0
Extend `src_to_module` function to handle source prefix
avdv Aug 15, 2024
97157d4
Strip source prefix in haskell_haddock rule
avdv Aug 15, 2024
8b98f4a
Merge pull request #23 from MercuryTechnologies/cb/support-main-attri…
avdv Aug 15, 2024
0c79a6c
Filter boot files from GHC -M command line
aherrmann Aug 16, 2024
0c997eb
Handle boot files in module_mapping
aherrmann Aug 16, 2024
9488b23
Handle boot files in module graph
aherrmann Aug 16, 2024
c3a1a2a
Handle boot files in package deps
aherrmann Aug 16, 2024
46ff394
Support imports in boot files
aherrmann Aug 16, 2024
9762665
wording
aherrmann Aug 16, 2024
b811942
Improve error messages for GHC compilation failures
9999years May 14, 2024
020127f
Improve error messages for metadata generation
aherrmann Aug 16, 2024
30d9f0f
Merge pull request #2 from MercuryTechnologies/rebeccat/better-errors
aherrmann Aug 16, 2024
6b39d3c
Redirect GHC stdout to stderr
aherrmann Aug 16, 2024
8dbef29
Fix stubs merge conflict
aherrmann Aug 16, 2024
10b3e7c
Merge pull request #25 from MercuryTechnologies/stdout-to-stderr
aherrmann Aug 16, 2024
8c7e1a1
Add external_tools to haskell_library (#27)
wavewave Aug 18, 2024
12df020
Merge pull request #24 from MercuryTechnologies/boot-file-import
aherrmann Aug 20, 2024
d78eab9
Fix: Missing instance of external_tools_arg
aherrmann Aug 20, 2024
9fd7482
Merge pull request #29 from MercuryTechnologies/external-tools-arg-fixup
aherrmann Aug 20, 2024
8d567b6
Determine source prefix automatically in _compile_module
avdv Aug 15, 2024
d9dced8
Use inferred source_prefixes in _compile_module
avdv Aug 16, 2024
b52fc03
Move package conf actions into dynamic output
avdv Aug 16, 2024
8ca86cf
Infer source prefixes for exposed-modules and import-dirs
avdv Aug 16, 2024
66794b4
Revert "Strip source prefix in haskell_haddock rule"
avdv Aug 16, 2024
cbba36d
Properly handle html output with source prefixes
avdv Aug 16, 2024
46e8439
Handle source prefix for boot modules
avdv Aug 16, 2024
b86e03f
Revert "Add `src_strip_prefix` to `haskell_library` rule"
avdv Aug 16, 2024
fde1250
Revert "Add `src_strip_prefix` attribute"
avdv Aug 16, 2024
1c00e46
Refactor: move assignment to `stubs`
avdv Aug 16, 2024
1ccbb64
Revert "Extend `src_to_module` function to handle source prefix"
avdv Aug 16, 2024
8596ff2
Add `source_prefix` helper function
avdv Aug 16, 2024
c2e19cb
Use source_prefix function in _compile_module
avdv Aug 16, 2024
7f460c3
Use source_prefix function in _make_package
avdv Aug 16, 2024
ebf0d6b
Use source_prefix function in _haddock_dump_interface
avdv Aug 16, 2024
ce6a47b
Simplify handling of haddock html output generation
avdv Aug 19, 2024
f3c8782
Add `get_source_prefixes` function to haskell/utils and use it
avdv Aug 19, 2024
2abfed1
Merge pull request #26 from MercuryTechnologies/cb/infer-source-prefix
avdv Aug 21, 2024
1d1b833
lint: unused assignment
avdv Aug 21, 2024
e975fdb
lint: unused parameters
avdv Aug 21, 2024
60346fa
Remove left-over comment
avdv Aug 21, 2024
da8601e
Merge remote-tracking branch 'upstream/main' into mercury
avdv Aug 21, 2024
8cc31e5
Merge pull request #30 from MercuryTechnologies/cb/lint-cleanup
avdv Aug 21, 2024
e5caf3c
Use a separate package db when gathering package metadata
avdv Aug 20, 2024
b786caf
Merge pull request #31 from MercuryTechnologies/cb/multiple-source-dirs
avdv Aug 21, 2024
e55bba1
Add srcs_envs. configure environment variable per source. (#28)
wavewave Aug 21, 2024
2719e2f
Add hidden inputs when constructing cmd_args
avdv Aug 22, 2024
35a1c85
Adapt to new dynamic actions API
avdv Aug 22, 2024
947d80c
WIP adapt to dynamic actions API
avdv Aug 22, 2024
dcd1c3b
Make shared lib soname opaque (take 2)
andrewjcg Apr 16, 2024
c1d12e6
hidden
avdv Aug 22, 2024
9bbe2bf
Use original dynamic_actions API
avdv Aug 22, 2024
0e9d619
Adapt to new dynamic actions API
avdv Aug 22, 2024
9e8d097
Adapt to renaming breadth_first_traversal -> depth_first_traversal
avdv Aug 22, 2024
ec9edfe
Adapt to hidden API change
avdv Aug 22, 2024
f5ff27d
Support `exported_post_linker_flags` in `prebuilt_haskell_library`
andrewjcg Jun 20, 2024
7f585d6
Propagate link strategy to link groups linking
Aug 19, 2024
1057d70
Added record for filtered labels to links
Aug 19, 2024
485ec2b
Do not expose boot modules
aherrmann Aug 22, 2024
a19fe16
add missing srcs_envs in haskell_binary (#32)
wavewave Aug 22, 2024
368ede9
Remove invalid args
avdv Aug 23, 2024
8c6aee7
Remove duplicate assignment to haskell_toolchain
avdv Aug 23, 2024
9671dea
Adapt to new dynamic actions API
avdv Aug 23, 2024
f97ef59
Fix error about haskell_toolchain_library_impl not existing
avdv Aug 23, 2024
ec3b744
Merge pull request #35 from MercuryTechnologies/no-expose-boot
aherrmann Aug 23, 2024
1fa99b3
cxx: Add `cxx_merge_cpreprocessors_actions`
avdv Aug 23, 2024
5822aac
Adapt to new dynamic actions API
avdv Aug 23, 2024
29f8e1b
Cleanup
avdv Aug 23, 2024
f79ae13
Refactor
avdv Aug 23, 2024
85d131b
lint: Remove duplicate load of `HaskellLibraryInfoTSet`
avdv Aug 23, 2024
b8e1758
Merge remote-tracking branch 'origin/mercury' into mercury
avdv Aug 23, 2024
258e810
Check if dynamic values are available
avdv Aug 26, 2024
1c2966e
Fix invalid count of associated outputs for dep file
avdv Aug 26, 2024
fe0e369
Fix type mismatch for + operator
avdv Aug 26, 2024
9612924
Fix dynamic haddock implementation
avdv Aug 26, 2024
2a6ce6f
Cleanup
avdv Aug 26, 2024
5bf1a83
Refactor
avdv Aug 26, 2024
276cfab
Merge pull request #36 from MercuryTechnologies/cb/upgradde-buck2
avdv Aug 27, 2024
6c3a1f3
use --show-iface-abi-hash for extracting hash
wavewave Aug 21, 2024
515311a
fix bug, and make it concise.
wavewave Aug 27, 2024
030479b
Prevent loading of default package environment, suppress messages
avdv Aug 28, 2024
cd82e26
Merge pull request #37 from MercuryTechnologies/cb/show-iface-abi-hash
avdv Aug 28, 2024
84f970d
make compiler_flags be of arg type (#34)
wavewave Aug 30, 2024
1741158
compiler_flags : list[ArgLike], not list[str] in _common_compile_modu…
wavewave Sep 11, 2024
04a7339
Revive accidentally deleted srcs_envs after buck2 upgrade (#43)
wavewave Sep 11, 2024
ff191d4
use_argsfile_at_link to use response file for a large number of objec…
wavewave Sep 12, 2024
de7f2c4
Generating dependency graph should include boot files (#38)
wavewave Oct 2, 2024
bb6b4b5
Dedupe attribute lists of deps
ndmitchell Apr 18, 2024
9c7e0a5
Use `at_argfile` helper
avdv Sep 16, 2024
f6af740
Remove left-over comment
avdv Sep 16, 2024
feb843f
Add performance optimisations for handling package DBs
avdv Sep 17, 2024
569d53c
Move package db selection before the loop
avdv Sep 17, 2024
edfa2d1
Use attr_deps_haskell_toolchain_libraries
avdv Sep 17, 2024
5494f65
Remove `exposed_package_libs`
avdv Sep 17, 2024
dd7fce1
Reformat
avdv Sep 17, 2024
23539aa
Convert cxx toolchain LinkerType to enum
Sep 9, 2024
faa08fd
Fix haskell_ghci() for multi-version GHC
Aug 22, 2024
c02667a
Rename relative args -> args
chatura-atapattu May 2, 2024
b65c1ac
Optimise generating ghci targets
ndmitchell Apr 26, 2024
62a4e33
Gracefully handle `None` values for ghci
avdv Sep 18, 2024
801a782
Avoid list["xxx"] in prelude
stepancheg Sep 26, 2024
f66d6e9
Remove boot files from ghc command line
avdv Oct 24, 2024
de61634
Merge pull request #45 from MercuryTechnologies/cb/import-changes-fro…
avdv Oct 24, 2024
e588c99
pkgname adjustment avoiding --. (#51)
wavewave Oct 30, 2024
1bc53ba
Base doesn't have to be special (#40)
wavewave Oct 30, 2024
4541453
Adapt to dynamic output API changes
avdv Oct 30, 2024
bc753a1
Prevent loading of default package environment for haddock actions
avdv Nov 1, 2024
8ab5fd2
use -fwrite-if-simplified-core to avoid unused bytecode generation
tek Nov 4, 2024
390ffd5
Merge pull request #53 from MercuryTechnologies/cb/upgrade-buck2
avdv Nov 6, 2024
05ee50b
Parallel downsweep (#46)
wavewave Nov 6, 2024
913d64f
Use argfile for stub dir copy if use_argfile_at_link is on (#52)
wavewave Nov 6, 2024
18b32bc
Allow cache upload for local action (#55)
wavewave Nov 6, 2024
1f0991a
Remove -x from stub collection action script
tek Nov 7, 2024
0fec69d
Pass -v0 to ghc-pkg register to reduce warning spam
tek Nov 8, 2024
ece0c27
Do not use `--reflink=auto` for `cp` command
avdv Nov 13, 2024
9997b1a
Refactor: add output artifact to haskell_haddock action
avdv Nov 13, 2024
a4c42f4
Merge pull request #59 from MercuryTechnologies/cb/re-on-macos
avdv Nov 14, 2024
12393f2
extra_libraries. native C/C++ libraries can be provided.
wavewave Nov 6, 2024
80f08b5
pass worker-id
wavewave Oct 9, 2024
ea497ae
hand pkgname as --worker-id
wavewave Oct 9, 2024
640e7bd
--worker-close
wavewave Oct 10, 2024
0625492
bug fix
wavewave Oct 10, 2024
7f25e72
fix incompatibility with argsfile
wavewave Oct 11, 2024
e958a14
not pass worker-* if use_persistent_workers=False
wavewave Oct 11, 2024
a786686
worker-id -> worker-target-id
wavewave Oct 15, 2024
77611a5
for now, show-iface-abi-hash has its own target-id.
wavewave Oct 17, 2024
e4aa376
haskell_metadata as a worker-target-id
wavewave Oct 28, 2024
ee578bc
show-iface-abi-hash worker only when persistent workers are used.
wavewave Oct 28, 2024
068a6b2
handle pkgname = None case
wavewave Oct 30, 2024
5adae04
introduce module_prefix.
wavewave Dec 20, 2024
e14e57b
-fpackage-db-byte-code
wavewave Dec 24, 2024
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
1 change: 1 addition & 0 deletions android/android_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ AndroidToolchainInfo = provider(
"bundle_builder": provider_field(typing.Any, default = None),
"combine_native_library_dirs": provider_field(typing.Any, default = None),
"d8_command": provider_field(typing.Any, default = None),
"enabled_voltron_non_asset_libs": provider_field(typing.Any, default = None),
"exo_resources_rewriter": provider_field(typing.Any, default = None),
"exopackage_agent_apk": provider_field(typing.Any, default = None),
"filter_dex_class_names": provider_field(typing.Any, default = None),
Expand Down
138 changes: 138 additions & 0 deletions apple/tools/linker_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

import argparse
import enum
import re
import subprocess
import sys

from typing import List, Optional, Tuple


def _eprintln(msg: str) -> None:
print(msg, flush=True, file=sys.stderr)


def _expand_arg_files(args: List[str]) -> List[str]:
expanded_args = []
for arg in args:
if arg.startswith("@"):
with open(arg[1:]) as argfile:
expanded_args.extend(
[line.strip('"') for line in argfile.read().splitlines()]
)
else:
expanded_args.append(arg)
return expanded_args


def _seperate_wrapper_args_from_linker_args(
args: List[str],
) -> Tuple[List[str], List[str]]:
wrapper_args = []
linker_args = []
expanded_args = _expand_arg_files(args)

i = 0
while i < len(expanded_args):
if expanded_args[i] == "-Xwrapper":
wrapper_args.append(expanded_args[i + 1])
i += 1
else:
linker_args.append(expanded_args[i])
i += 1

return wrapper_args, linker_args


def _diagnose_potential_unexported_symbol_issue(
unexported_symbol_lists: List[str], stderr: str
) -> Optional[str]:
stderr_lines = stderr.splitlines()
undefined_symbol_re = re.compile(r"undefined symbol:.*\(mangled: (\S+)\)")
undefined_symbols = set()
for stderr_line in stderr_lines:
match = re.search(undefined_symbol_re, stderr_line)
if match:
undefined_symbols.add(match.group(1))

if not undefined_symbols:
return None

unexported_symbols = set()
incorrectly_unexported_symbols = set()
incorrect_unexported_symbol_lists = []
for unexported_symbol_list in unexported_symbol_lists:
target_name, file_path = unexported_symbol_list.split(",")
with open(file_path, "r") as unexported_symbol_list_file:
unexported_symbols = set(unexported_symbol_list_file.read().splitlines())
intersection = undefined_symbols & unexported_symbols
if intersection:
incorrectly_unexported_symbols.update(intersection)
incorrect_unexported_symbol_lists.append(target_name)

if not incorrect_unexported_symbol_lists:
return None

return f"""
UNEXPORTED SYMBOLS ERROR:

At least one symbol is included in an unexported symbol list, but referenced across dylib boundaries. Please
run the following command to fix the unexported symbol lists:

arc fix-unexported-symbol-lists {"".join(["--target " + target for target in incorrect_unexported_symbol_lists])} {" ".join(["--symbol " + symbol for symbol in sorted(incorrectly_unexported_symbols)])}

Here is the linker failure message:
"""


class Linker(enum.Enum):
LLD = "lld"
LD64 = "ld64"


def _discover_linker(args: List[str]) -> Optional[Linker]:
for arg in args:
if arg.startswith("-fuse-ld="):
linker_name = arg.split("=")[-1]
if linker_name == Linker.LLD.value:
return Linker.LLD
elif linker_name == Linker.LD64.value:
return Linker.LD64
else:
raise Exception(f"Unknown linker: {linker_name}")


def main(argv: List[str]) -> int:
wrapper_args, linker_args = _seperate_wrapper_args_from_linker_args(argv[1:])

parser = argparse.ArgumentParser()
parser.add_argument("-linker")
parser.add_argument("-unexported_symbol_list", action="append")
args = parser.parse_args(wrapper_args)

linker = _discover_linker(linker_args)
if linker == Linker.LLD:
linker_args.extend(
["-Xlinker", "-pika_include_mangled_names_in_undefined_symbol_errors"]
)

result = subprocess.run([args.linker] + linker_args, capture_output=True, text=True)
if result.returncode != 0:
if args.unexported_symbol_list and linker == Linker.LLD:
diagnosis = _diagnose_potential_unexported_symbol_issue(
args.unexported_symbol_list, result.stderr
)
if diagnosis:
_eprintln(diagnosis)
_eprintln(result.stderr)
return result.returncode


if __name__ == "__main__":
sys.exit(main(sys.argv))
18 changes: 11 additions & 7 deletions cxx/anon_link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ load(
"ArtifactInfo",
"make_artifact_tset",
)
load("@prelude//cxx:cxx_toolchain_types.bzl", "CxxToolchainInfo")
load(
"@prelude//cxx:cxx_toolchain_types.bzl",
"CxxToolchainInfo",
"LinkerType",
)
load("@prelude//cxx:cxx_utility.bzl", "cxx_attrs_get_allow_cache_upload")
load("@prelude//linking:execution_preference.bzl", "LinkExecutionPreference")
load(
Expand All @@ -34,15 +38,15 @@ def _serialize_linkable(linkable):
return ("archive", (
(linkable.archive.artifact, linkable.archive.external_objects),
linkable.link_whole,
linkable.linker_type,
linkable.linker_type.value,
linkable.supports_lto,
))

if isinstance(linkable, ObjectsLinkable):
return ("objects", (
linkable.objects,
linkable.link_whole,
linkable.linker_type,
linkable.linker_type.value,
))

if isinstance(linkable, SharedLibLinkable):
Expand Down Expand Up @@ -107,7 +111,7 @@ def _deserialize_linkable(linkable: (str, typing.Any)) -> typing.Any:
external_objects = external_objects,
),
link_whole = link_whole,
linker_type = linker_type,
linker_type = LinkerType(linker_type),
supports_lto = supports_lto,
)

Expand All @@ -116,7 +120,7 @@ def _deserialize_linkable(linkable: (str, typing.Any)) -> typing.Any:
return ObjectsLinkable(
objects = objects,
link_whole = link_whole,
linker_type = linker_type,
linker_type = LinkerType(linker_type),
)

if typ == "shared":
Expand Down Expand Up @@ -207,7 +211,7 @@ ANON_ATTRS = {
# ObjectsLinkable
attrs.list(attrs.source()), # objects
attrs.bool(), # link_whole
attrs.string(), # linker_type
attrs.enum(LinkerType.values()), # linker_type
),
attrs.tuple(
# ArchiveLinkable
Expand All @@ -217,7 +221,7 @@ ANON_ATTRS = {
attrs.list(attrs.source()), # external_objects
),
attrs.bool(), # link_whole
attrs.string(), # linker_type
attrs.enum(LinkerType.values()), # linker_type
attrs.bool(), # supports_lto
),
attrs.tuple(
Expand Down
6 changes: 3 additions & 3 deletions cxx/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

load("@prelude//cxx:cxx_toolchain_types.bzl", "LinkerInfo")
load("@prelude//cxx:cxx_toolchain_types.bzl", "LinkerInfo", "LinkerType")
load("@prelude//linking:link_info.bzl", "Archive")
load("@prelude//utils:argfile.bzl", "at_argfile")
load("@prelude//utils:utils.bzl", "value_or")
load(":cxx_context.bzl", "get_cxx_toolchain_info")

def _archive_flags(
archiver_type: str,
linker_type: str,
linker_type: LinkerType,
use_archiver_flags: bool,
symbol_table: bool,
thin: bool) -> list[str]:
Expand Down Expand Up @@ -43,7 +43,7 @@ def _archive_flags(
flags += "T"

# GNU archivers support generating deterministic archives.
if linker_type == "gnu":
if linker_type == LinkerType("gnu"):
flags += "D"

return [flags]
Expand Down
1 change: 1 addition & 0 deletions cxx/comp_db.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load(":cxx_context.bzl", "get_cxx_toolchain_info")

# Provider that exposes the compilation database information
CxxCompilationDbInfo = provider(fields = {
"compdb": provider_field(typing.Any, default = None), # path customly built compile_commands.json (used by Zephyr projects)
"info": provider_field(typing.Any, default = None), # A map of the file (an `Artifact`) to its corresponding `CxxSrcCompileCommand`
"platform": provider_field(typing.Any, default = None), # platform for this compilation database
"toolchain": provider_field(typing.Any, default = None), # toolchain for this compilation database
Expand Down
11 changes: 8 additions & 3 deletions cxx/cxx_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ load(
"cxx_use_shlib_intfs",
"cxx_use_shlib_intfs_mode",
)
load(":cxx_toolchain_types.bzl", "ShlibInterfacesMode", "is_bitcode_format")
load(
":cxx_toolchain_types.bzl",
"LinkerType",
"ShlibInterfacesMode",
"is_bitcode_format",
)
load(
":cxx_types.bzl",
"CxxRuleConstructorParams", # @unused Used as a type
Expand Down Expand Up @@ -1173,7 +1178,7 @@ def _strip_objects(ctx: AnalysisContext, objects: list[Artifact]) -> list[Artifa

# Stripping is not supported on Windows
linker_type = cxx_toolchain_info.linker_info.type
if linker_type == "windows":
if linker_type == LinkerType("windows"):
return objects

# Disable stripping if no `strip` binary was provided by the toolchain.
Expand Down Expand Up @@ -1373,7 +1378,7 @@ def _static_library(
# On darwin, the linked output references the archive that contains the
# object files instead of the originating objects.
object_external_debug_info = []
if linker_type == "darwin":
if linker_type == LinkerType("darwin"):
object_external_debug_info.append(archive.artifact)
object_external_debug_info.extend(archive.external_objects)
elif objects_have_external_debug_info:
Expand Down
8 changes: 6 additions & 2 deletions cxx/cxx_library_utility.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ load(
"from_named_set",
)
load(":cxx_context.bzl", "get_cxx_platform_info", "get_cxx_toolchain_info")
load(":cxx_toolchain_types.bzl", "ShlibInterfacesMode")
load(
":cxx_toolchain_types.bzl",
"LinkerType",
"ShlibInterfacesMode",
)
load(
":headers.bzl",
"cxx_attr_header_namespace",
Expand Down Expand Up @@ -143,7 +147,7 @@ def cxx_attr_resources(ctx: AnalysisContext) -> dict[str, ArtifactOutputs]:
return resources

def cxx_is_gnu(ctx: AnalysisContext) -> bool:
return get_cxx_toolchain_info(ctx).linker_info.type == "gnu"
return get_cxx_toolchain_info(ctx).linker_info.type == LinkerType("gnu")

def cxx_use_shlib_intfs(ctx: AnalysisContext) -> bool:
"""
Expand Down
18 changes: 11 additions & 7 deletions cxx/cxx_link_utility.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

load("@prelude//:artifact_tset.bzl", "project_artifacts")
load("@prelude//:paths.bzl", "paths")
load("@prelude//cxx:cxx_toolchain_types.bzl", "CxxToolchainInfo")
load(
"@prelude//cxx:cxx_toolchain_types.bzl",
"CxxToolchainInfo",
"LinkerType",
)
load("@prelude//cxx:debug.bzl", "SplitDebugMode")
load("@prelude//cxx:linker.bzl", "get_rpath_origin")
load("@prelude//cxx:target_sdk_version.bzl", "get_target_sdk_version_linker_flags")
Expand Down Expand Up @@ -42,14 +46,14 @@ def generates_split_debug(toolchain: CxxToolchainInfo):

def linker_map_args(toolchain: CxxToolchainInfo, linker_map) -> LinkArgs:
linker_type = toolchain.linker_info.type
if linker_type == "darwin":
if linker_type == LinkerType("darwin"):
flags = [
"-Xlinker",
"-map",
"-Xlinker",
linker_map,
]
elif linker_type == "gnu":
elif linker_type == LinkerType("gnu"):
flags = [
"-Xlinker",
"-Map",
Expand Down Expand Up @@ -98,7 +102,7 @@ def make_link_args(
linker_info = cxx_toolchain_info.linker_info
linker_type = linker_info.type

if linker_type == "darwin":
if linker_type == LinkerType("darwin"):
# Darwin requires a target triple specified to
# control the deployment target being linked for.
args.add(get_target_sdk_version_linker_flags(ctx))
Expand Down Expand Up @@ -132,7 +136,7 @@ def make_link_args(
hidden.append(pdb_artifact.as_output())

filelists = None
if linker_type == "darwin":
if linker_type == LinkerType("darwin"):
filelists = filter(None, [unpack_link_args_filelist(link) for link in links])
hidden.extend(filelists)

Expand Down Expand Up @@ -196,7 +200,7 @@ def cxx_sanitizer_runtime_arguments(
if not linker_info.sanitizer_runtime_files:
fail("C++ sanitizer runtime enabled but there are no runtime files")

if linker_info.type == "darwin":
if linker_info.type == LinkerType("darwin"):
# ignore_artifacts as the runtime directory is not required at _link_ time
runtime_rpath = cmd_args(ignore_artifacts = True)
runtime_files = linker_info.sanitizer_runtime_files
Expand Down Expand Up @@ -247,7 +251,7 @@ def executable_shared_lib_arguments(
linker_type = cxx_toolchain.linker_info.type

if len(shared_libs) > 0:
if linker_type == "windows":
if linker_type == LinkerType("windows"):
shared_libs_symlink_tree = [ctx.actions.symlink_file(
shlib.lib.output.basename,
shlib.lib.output,
Expand Down
Loading