# -*- mode: python -*-

Import([
    "env",
    "get_option",
    "has_option",
    "inmemory",
    "version_extra",
    "version_parts",
    "wiredtiger",
])

env = env.Clone()

# Ideally 's2' would be scoped narrowly but it is spammed in all over the place by
# db/geo unfortunately.
env.InjectThirdParty(libraries=[
    's2',
])

env.SConscript(
    dirs=[
        'auth',
        'backup',
        'bson',
        'catalog',
        'commands',
        'concurrency',
        'cst',
        'encryption',
        'exec',
        'fts',
        'ftdc',
        'geo',
        'process_health',
        'index',
        'ldap',
        'matcher',
        'op_observer',
        'ops',
        'pipeline',
        'query',
        'repl',
        's',
        'serverless',
        'session',
        'sorter',
        'stats',
        'storage',
        'telemetry',
        'timeseries',
        'transaction',
        'update',
        'views',
    ],
    exports=[
        'env',
    ],
)

# The 'server_base' library must only contain basic, stateless, value types which are used throughout
# all the server binaries. It must not depend on anything other than utilities that are outside of
# the server codebase.
env.Library(
    target='server_base',
    source=[
        'basic_types.idl',
        'catalog_shard_feature_flag.idl',
        'cluster_role.cpp',
        'feature_compatibility_version_document.idl',
        'feature_compatibility_version_parser.cpp',
        'feature_flag.cpp',
        'index_names.cpp',
        'keypattern.cpp',
        'logical_time.cpp',
        'multitenancy.idl',
        'namespace_string.cpp',
        'server_options.cpp',
        'server_parameter.cpp',
        'server_parameter.idl',
        'server_parameter_with_storage.cpp',
        'shard_id.cpp',
        'shutdown_in_progress_quiesce_info.cpp',
        'tenant_id.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/idl/idl_parser',
    ],
)

#
# The db/'common' lib has the abstractions that are shared by components of the
# server. Ideally, many of the object in 'coredb' should be moved here when their dependencies
# get resolved.
#

env.Library(
    target='common',
    source=[
        'field_ref.cpp',
        'field_ref_set.cpp',
        'field_parser.cpp',
        'txn_retry_counter_too_old_info.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/catalog/cannot_convert_index_to_unique_info',
        '$BUILD_DIR/mongo/db/repl/tenant_migration_errors',
        '$BUILD_DIR/mongo/db/write_concern_options',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info',
        'server_base',
    ],
)

env.Library(
    target='global_index',
    source=[
        'global_index.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/catalog/clustered_collection_options',
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        '$BUILD_DIR/mongo/db/session/logical_session_id_helpers',
        '$BUILD_DIR/mongo/db/storage/key_string',
        '$BUILD_DIR/mongo/db/transaction/transaction',
        'index_builds_coordinator_interface',
        'query_exec',
        'shard_role',
    ],
)

env.Library(
    target='multitenancy',
    source=[
        'multitenancy.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/security_token',
        'server_base',
        'server_feature_flags',
    ],
)

env.Library(
    target='dbmessage',
    source=[
        'dbmessage.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/bson/bson_validate',
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        '$BUILD_DIR/mongo/util/net/network',
        'server_base',
    ],
)

env.Library(
    target='startup_warnings_common',
    source=[
        'startup_warnings_common.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/authentication',
        '$BUILD_DIR/mongo/util/net/ssl_manager',
    ],
)

env.Library(
    target='startup_warnings_mongod',
    source=[
        'startup_warnings_mongod.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        '$BUILD_DIR/mongo/db/repl/repl_settings',
        '$BUILD_DIR/mongo/util/processinfo',
        'startup_warnings_common',
    ],
)

env.Library(
    target='profile_filter',
    source=[
        'profile_filter.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
)

env.Library(
    target='curop_failpoint_helpers',
    source=[
        'curop_failpoint_helpers.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/query/query_stats/query_stats',
        '$BUILD_DIR/mongo/util/fail_point',
    ],
)

env.Library(
    target='mongohasher',
    source=[
        'hasher.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/util/md5',
    ],
)

env.Library(
    target='update_index_data',
    source=[
        'update_index_data.cpp',
    ],
    LIBDEPS=[
        'common',
    ],
)

env.Library(
    target='collection_index_usage_tracker',
    source=[
        'aggregated_index_usage_tracker.cpp',
        'collection_index_usage_tracker.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/server_status_core',
        'server_base',
    ],
)

env.Command(
    target=[
        'feature_flag_test.idl',
    ],
    source=[
        '#buildscripts/cheetah_source_generator.py',
        'feature_flag_test.idl.tpl',
        '$BUILD_DIR/mongo/util/version/releases.yml',
    ],
    action=[
        '$PYTHON ${SOURCES[0]} -o ${TARGETS[0]} ${SOURCES[1]} ${SOURCES[2]} ${MONGO_VERSION}',
    ],
    # Ensure that that SCons is used to produce this file rather than Ninja, to avoid spurious
    # dependency cycles due to how we manage generated sources with Ninja.
    NINJA_TEMPLATE=True,
)

env.Library(
    target='server_feature_flags',
    source=[
        'feature_flag_test.idl',
        'server_feature_flags.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/idl/cluster_server_parameter',
        'server_base',
    ],
)

env.Library(
    target='server_options',
    source=[
        'redaction_parameter.cpp',
        'redaction_parameter.idl',
        'server_options_helpers.cpp',
        'server_options_helpers.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/cmdline_utils/cmdline_utils',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/fail_point',
        'server_base',
    ],
)

if env.TargetOSIs('windows'):
    env.Library(
        target='windows_options',
        source=[
            'windows_options.idl',
        ],
        LIBDEPS_PRIVATE=[
            '$BUILD_DIR/mongo/util/options_parser/options_parser',
        ],
    )

env.Library(
    target='ldap_options',
    source=[
        'ldap_options.cpp',
        'ldap_options.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/server_base',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
    ],
)

env.Library(
  target='ldap_options_init',
  source=[
      'ldap_options_init.cpp',
  ],
  LIBDEPS=[
    'ldap_options'
  ],
  LIBDEPS_PRIVATE=[
       '$BUILD_DIR/mongo/util/net/network',
       '$BUILD_DIR/mongo/util/options_parser/options_parser',
  ],
)     

env.Library(
    target='server_options_base',
    source=[
        'server_options_base.cpp',
        'cluster_auth_mode_option.idl',
        'keyfile_option.idl',
        'server_options_base.idl',
        'server_options_general.idl',
        'server_options_nongeneral.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/cluster_auth_mode',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
        'connection_health_metrics_parameter',
        'server_base',
    ],
)

env.Clone().InjectModule("enterprise").Library(
    target='server_options_servers',
    source=[
        'server_options_server_helpers.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/transport/message_compressor',
        '$BUILD_DIR/mongo/util/net/network',
        # The dependency on net/ssl_manager is a temporary crutch that should go away once the
        # networking library has separate options
        '$BUILD_DIR/mongo/util/net/ssl_manager',
        'server_options',
        'server_options_base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/cluster_auth_mode',
        'server_base',
    ],
)

env.Library(
    target="serverinit",
    source=[
        "initialize_server_global_state.cpp",
        "initialize_server_global_state.idl",
        "server_options_init.cpp",
    ],
    LIBDEPS_PRIVATE=[
        "$BUILD_DIR/mongo/db/audit",
        "$BUILD_DIR/mongo/util/processinfo",
        "$BUILD_DIR/mongo/util/signal_handlers",
    ],
)

env.Library(
    target="global_settings",
    source=[
        "global_settings.cpp",
    ],
    LIBDEPS=[
        'encryption/encryption_options',
        'repl/repl_settings',
        'service_context',
    ],
)

env.Library(
    target="connection_health_metrics_parameter",
    source=[
        "connection_health_metrics_parameter.idl",
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/server_base',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
    ],
)

# mongod options
env.Library(
    target="mongod_options",
    source=[
        "mongod_options.cpp",
        "ratelimit_parameter.cpp",
        'mongod_options_encryption.idl',
        'mongod_options_general.idl',
        'mongod_options_ldapauthz.idl',
        'mongod_options_legacy.idl',
        'mongod_options_removed.idl',
        'mongod_options_replication.idl',
        'mongod_options_sharding.idl',
        'mongod_options_storage.idl',
        'ratelimit_parameter.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/cluster_auth_mode',
        '$BUILD_DIR/mongo/db/ldap_options',
        '$BUILD_DIR/mongo/db/repl/repl_settings',
        '$BUILD_DIR/mongo/db/repl/replica_set_messages',
        '$BUILD_DIR/mongo/db/storage/storage_options',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
        'global_settings',
        'server_base',
        'server_options_base',
        'server_options_servers',
    ],
)

env.Library(
    target='read_write_concern_provenance',
    source=[
        'read_write_concern_provenance.cpp',
        'read_write_concern_provenance_base.idl',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
    ],
)

env.Library(
    target='write_concern_options',
    source=[
        'write_concern_options.cpp',
        'write_concern_options.idl',
    ],
    LIBDEPS=[
        'read_write_concern_provenance',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
        'server_base',
    ],
)

env.Library(
    target='read_write_concern_defaults',
    source=[
        'read_write_concern_defaults.cpp',
        'read_write_concern_defaults.idl',
    ],
    LIBDEPS=[
        'repl/read_concern_args',
        'write_concern_options',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/repl/repl_server_parameters',
        '$BUILD_DIR/mongo/util/caching',
        '$BUILD_DIR/mongo/util/concurrency/thread_pool',
        'server_base',
        'vector_clock',
    ],
)

env.Library(
    target='change_stream_options',
    source=[
        'change_stream_options.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/idl/cluster_server_parameter',
        'server_base',
    ],
)

env.Library(
    target='change_stream_options_manager',
    source=[
        'change_stream_options_manager.cpp',
        'change_stream_options_parameter.idl',
    ],
    LIBDEPS_PRIVATE=[
        'change_stream_options',
        'change_stream_serverless_helpers',
        'repl/repl_coordinator_interface',
        'server_base',
        'service_context',
    ],
)

env.Library(
    target='change_streams_cluster_parameter',
    source=[
        'change_streams_cluster_parameter.idl',
        'change_streams_cluster_parameter.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        '$BUILD_DIR/mongo/idl/cluster_server_parameter',
        'change_stream_serverless_helpers',
        'server_base',
    ],
)

env.Library(
    target='change_stream_state',
    source=[
        'change_stream_state.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        'server_base',
    ],
)

env.Library(
    target='set_change_stream_state_coordinator',
    source=[
        'set_change_stream_state_coordinator.cpp',
        'set_change_stream_state_coordinator.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/change_stream_change_collection_manager',
        '$BUILD_DIR/mongo/db/change_stream_pre_images_collection_manager',
        '$BUILD_DIR/mongo/db/change_stream_serverless_helpers',
        '$BUILD_DIR/mongo/db/change_stream_state',
        '$BUILD_DIR/mongo/db/dbdirectclient',
        '$BUILD_DIR/mongo/db/repl/primary_only_service',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        '$BUILD_DIR/mongo/db/repl/wait_for_majority_service',
        '$BUILD_DIR/mongo/idl/idl_parser',
    ],
)

env.Library(
    target='change_stream_serverless_helpers',
    source=[
        'change_stream_serverless_helpers.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'catalog/collection_catalog',
        'global_settings',
        'query/query_knobs',
        'server_base',
    ],
)

env.Library(
    target='change_stream_change_collection_manager',
    source=[
        'change_collection_truncate_markers.cpp',
        'change_stream_change_collection_manager.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
        '$BUILD_DIR/mongo/db/catalog/clustered_collection_options',
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/change_stream_serverless_helpers',
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        '$BUILD_DIR/mongo/db/dbhelpers',
        '$BUILD_DIR/mongo/db/server_feature_flags',
        '$BUILD_DIR/mongo/db/service_context',
    ],
)

env.Library(
    target='change_collection_expired_change_remover',
    source=[
        'change_collection_expired_documents_remover.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/change_stream_change_collection_manager',
        '$BUILD_DIR/mongo/db/change_stream_serverless_helpers',
        '$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
        '$BUILD_DIR/mongo/db/query_exec',
        '$BUILD_DIR/mongo/util/periodic_runner',
    ],
)

env.Library(
    target='change_stream_pre_images_collection_manager',
    source=[
        'change_stream_pre_images_collection_manager.cpp',
        'change_stream_pre_images_truncate_markers.cpp'
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/pipeline/change_stream_preimage',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
        '$BUILD_DIR/mongo/db/catalog/clustered_collection_options',
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        '$BUILD_DIR/mongo/db/repl/storage_interface',
        'change_stream_options_manager',
        'change_stream_serverless_helpers',
        'query_exec',
        'record_id_helpers',
        'server_base',
    ],
)

env.Library(
    target='write_block_bypass',
    source=[
        'write_block_bypass.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'auth/auth',
        'service_context',
    ],
)

env.Library(
    target="read_write_concern_defaults_mock",
    source=[
        "read_write_concern_defaults_cache_lookup_mock.cpp",
    ],
    LIBDEPS=[
        'read_write_concern_defaults',
    ],
)

env.Library(
    target='service_context',
    source=[
        'baton.cpp',
        'cancelable_operation_context.cpp',
        'client.cpp',
        'client_strand.cpp',
        'default_baton.cpp',
        'operation_context.cpp',
        'operation_context_group.cpp',
        'operation_cpu_timer.cpp',
        'operation_id.cpp',
        'operation_key_manager.cpp',
        'service_context.cpp',
        'server_recovery.cpp',
        'repl_set_member_in_standalone_mode.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/multi_key_path_tracker',
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        '$BUILD_DIR/mongo/db/storage/recovery_unit_base',
        '$BUILD_DIR/mongo/db/storage/write_unit_of_work',
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/concurrency/spin_lock',
        '$BUILD_DIR/mongo/util/fail_point',
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/periodic_runner',
        'write_concern_options',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/storage/storage_change_lock',
        '$BUILD_DIR/mongo/util/processinfo',
    ],
)

env.Library(
    target='prepare_conflict_tracker',
    source=[
        'prepare_conflict_tracker.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/service_context',
    ],
)

env.Library(
    target='multi_key_path_tracker',
    source=[
        'multi_key_path_tracker.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/storage/key_string',
    ],
)

env.Library(
    target='not_primary_error_tracker',
    source=[
        "not_primary_error_tracker.cpp",
    ],
    LIBDEPS=[
        'service_context',
    ],
)

audit_libdeps = [
    '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
    '$BUILD_DIR/mongo/db/query_expressions',
    '$BUILD_DIR/mongo/db/server_base',
    '$BUILD_DIR/mongo/util/background_job',
]
if has_option('audit'):
    # The Percona's `audit` library is intended to be a drop-in replacement of
    # the upstream `audit` (please @see the `else` branch). Hense, it has to
    # have the same filepath and set of dependencies as the upstream `audit`
    # has. That's why the Percona's `audit` library is built here rather than in
    # the `src/mongo/db/audit` directory.
    env.Library(
        target='audit',
        source=[
            'audit.cpp',
            'audit/audit_flusher.cpp',
            'audit/audit_options.cpp',
            'audit/audit.cpp',
            'audit/audit_parameters.idl',
            'audit/audit_options.idl',
        ],
        LIBDEPS=audit_libdeps,
    )
    # Please note that the `commands` library (@see below) depends on
    # the `audit` library and the `audit_commands` depends on `commands`.
    #
    # Since the Percona's `audit` library is built in this file, it is natural
    # to build `audit_commands` here as well rather than in
    # the `src/mongo/db/audit` directory.
    env.Library(
        target='audit_commands',
        source=[
            'audit/audit_commands.cpp',
        ],
        LIBDEPS_PRIVATE=[
            '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
            'audit',
            'commands'
        ],
    )
else:
    env.Clone().InjectModule("enterprise").Library(
        target="audit",
        source=[
            "audit.cpp",
        ],
        LIBDEPS=audit_libdeps,
    )

env.Library(
    target='client_out_of_line_executor',
    source=[
        'client_out_of_line_executor.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/service_context',
    ],
)

env.Library(
    target='mirror_maestro',
    source=[
        'mirror_maestro.cpp',
        'mirror_maestro.idl',
        'mirroring_sampler.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/executor/task_executor_interface',
        '$BUILD_DIR/mongo/rpc/message',
        '$BUILD_DIR/mongo/util/net/network',
        'client_out_of_line_executor',
        'service_context',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
        '$BUILD_DIR/mongo/executor/network_interface_factory',
        '$BUILD_DIR/mongo/executor/thread_pool_task_executor',
        '$BUILD_DIR/mongo/util/concurrency/thread_pool',
        'commands',
        'commands/server_status_core',
        'repl/repl_coordinator_interface',
        'repl/replica_set_messages',
        'repl/topology_version_observer',
        'server_base',
    ],
)

env.CppUnitTest(
    target='client_out_of_line_executor_test',
    source=[
        'client_out_of_line_executor_test.cpp',
    ],
    LIBDEPS=[
        'client_out_of_line_executor',
    ],
)

env.Library(
    target="coll_mod_command_idl",
    source=[
        'coll_mod.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/catalog/collection_options',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/authprivilege',
        '$BUILD_DIR/mongo/db/timeseries/timeseries_options',
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        'server_base',
    ],
)

env.Library(
    target='dbcommands_idl',
    source=[
        'dbcommands.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/pipeline/document_sources_idl',
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        'server_base',
    ],
)

env.Library(
    target="metadata_consistency_types_idl",
    source=[
        'metadata_consistency_types.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        'server_base',
    ],
)

env.Library(
    target='commands',
    source=[
        'coll_mod_reply_validation.cpp',
        'commands.cpp',
        'curop.cpp',
        'drop.idl',
        'drop_database.idl',
        'explain.idl',
        'list_collections.idl',
        'list_indexes.idl',
    ],
    LIBDEPS=[
        'api_parameters',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/bson/mutable/mutable_bson',
        '$BUILD_DIR/mongo/rpc/command_status',
        '$BUILD_DIR/mongo/rpc/rewrite_state_change_errors',
        '$BUILD_DIR/mongo/rpc/rpc',
        '$BUILD_DIR/mongo/transport/service_executor',
        '$BUILD_DIR/mongo/util/concurrency/admission_context',
        '$BUILD_DIR/mongo/util/diagnostic_info'
        if get_option('use-diagnostic-latches') == 'on' else [],
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        '$BUILD_DIR/mongo/util/progress_meter',
        'audit',
        'auth/auth',
        'auth/authprivilege',
        'auth/user_acquisition_stats',
        'catalog/collection_options',
        'coll_mod_command_idl',
        'commands/create_command',
        'commands/server_status_core',
        'commands/test_commands_enabled',
        'concurrency/lock_manager',
        'generic_cursor',
        'index_commands_idl',
        'pipeline/change_stream_pre_and_post_images_options',
        'prepare_conflict_tracker',
        'query/common_query_enums_and_helpers',
        'repl/read_concern_args',
        'server_base',
        'stats/resource_consumption_metrics',
        'stats/timer_stats',
        # TODO (SERVER-66896): Remove this dependency.
        'storage/storage_engine_feature_flags',
        'timeseries/timeseries_options',
    ],
)

env.Library(
    target='command_can_run_here',
    source=[
        'command_can_run_here.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/client/read_preference',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        'commands/test_commands_enabled',
        'service_context',
    ],
)

env.Library(
    target='shard_role_api_stor_ex',
    source=[
        'catalog/collection.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/s/common_s',
        'catalog/clustered_collection_options',
        'catalog/index_catalog',
        'server_base',
    ],
)

env.Library(
    target='shard_role_api',
    source=[
        'catalog/collection_operation_source.cpp',
        's/collection_metadata.cpp',
        's/collection_sharding_state.cpp',
        's/collection_sharding_state_factory_standalone.cpp',
        's/database_sharding_state.cpp',
        's/global_user_write_block_state.cpp',
        's/operation_sharding_state.cpp',
        's/range_arithmetic.cpp',
        's/shard_key_index_util.cpp',
        's/sharding_api_d_params.idl',
        's/sharding_migration_critical_section.cpp',
        's/sharding_state.cpp',
        's/sharding_statistics.cpp',
        's/sharding_write_router.cpp',
        's/transaction_coordinator_curop.cpp',
        's/transaction_coordinator_factory.cpp',
        's/transaction_coordinator_worker_curop_repository.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/s/grid',
        'concurrency/lock_manager',
        'index/index_access_method',
        'shard_role_api_stor_ex',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
        'write_block_bypass',
    ],
)

env.Library(
    target='shard_role',
    source=[
        'catalog_raii.cpp',
        'catalog/catalog_helper.cpp',
        'catalog/collection_uuid_mismatch.cpp',
        'catalog/collection_yield_restore.cpp',
        'db_raii.cpp',
        'direct_connection_util.cpp',
    ],
    LIBDEPS=[
        'catalog/collection_catalog',
        'catalog/database_holder',
        'shard_role_api',
        'stats/top',
        'storage/write_unit_of_work',
        'views/views',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info',
        '$BUILD_DIR/mongo/db/catalog/local_oplog_info',
        'multitenancy',
        'server_base',
        'storage/capped_snapshots',
        'storage/snapshot_helper',
    ],
)

env.Library(
    target='internal_transactions_feature_flag',
    source=[
        'internal_transactions_feature_flag.idl',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
    ],
)

env.Library(
    target='fle_crud',
    source=[
        'commands/fle2_get_count_info_command.idl',
        'fle_crud.cpp',
        'query/fle/encrypted_predicate.cpp',
        'query/fle/equality_predicate.cpp',
        'query/fle/query_rewriter.cpp',
        'query/fle/range_predicate.cpp',
        'query/fle/range_validator.cpp',
        'query/fle/server_rewrite.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/crypto/encrypted_field_config',
        '$BUILD_DIR/mongo/db/ops/write_ops_parsers',
        '$BUILD_DIR/mongo/db/pipeline/pipeline',
        '$BUILD_DIR/mongo/db/query/command_request_response',
        '$BUILD_DIR/mongo/db/transaction/transaction_api',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/crypto/fle_crypto',
        '$BUILD_DIR/mongo/db/query/collation/collator_factory_interface',
        '$BUILD_DIR/mongo/db/query/query_request',
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        '$BUILD_DIR/mongo/executor/inline_executor',
        '$BUILD_DIR/mongo/executor/task_executor_pool',
        '$BUILD_DIR/mongo/s/grid',
        '$BUILD_DIR/mongo/s/sharding_router_api',
        'dbdirectclient',
        'query_expressions',
    ],
)

env.Library(
    target='fle_crud_mongod',
    source=[
        'fle_crud_mongod.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/crypto/fle_crypto',
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        '$BUILD_DIR/mongo/db/query/query_request',
        '$BUILD_DIR/mongo/db/record_id_helpers',
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        '$BUILD_DIR/mongo/db/session/session_catalog',
        '$BUILD_DIR/mongo/db/session/session_catalog_mongod',
        '$BUILD_DIR/mongo/db/transaction/transaction',
        '$BUILD_DIR/mongo/executor/inline_executor',
        '$BUILD_DIR/mongo/executor/network_interface_factory',
        '$BUILD_DIR/mongo/executor/task_executor_pool',
        '$BUILD_DIR/mongo/executor/thread_pool_task_executor',
        '$BUILD_DIR/mongo/s/grid',
        '$BUILD_DIR/mongo/util/concurrency/thread_pool',
        'fle_crud',
        'shard_role',
    ],
)

env.Library(
    target='fle_mocks',
    source=[
        'fle_query_interface_mock.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/crypto/fle_crypto',
        '$BUILD_DIR/mongo/db/ops/write_ops',
        '$BUILD_DIR/mongo/db/repl/storage_interface_impl',
        'fle_crud',
        'fle_crud_mongod',
    ],
)

env.Library(
    target='cluster_transaction_api',
    source=[
        'cluster_transaction_api.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        '$BUILD_DIR/mongo/db/session/logical_session_id_helpers',
        '$BUILD_DIR/mongo/db/transaction/transaction_api',
        '$BUILD_DIR/mongo/rpc/rpc',
        '$BUILD_DIR/mongo/s/startup_initialization',
        '$BUILD_DIR/mongo/transport/service_entry_point',
        'service_context',
        'shared_request_handling',
    ],
)

env.Library(
    target='dbdirectclient',
    source=[
        'dbdirectclient.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/client/clientdriver_minimal',
        '$BUILD_DIR/mongo/db/query/query_stats/query_stats',
        'not_primary_error_tracker',
        'ops/write_ops_parsers',
    ],
    LIBDEPS_PRIVATE=[
        'repl/repl_coordinator_interface',
    ],
)

env.Library(
    target='dbhelpers',
    source=[
        'dbhelpers.cpp',
    ],
    LIBDEPS=[
        'index/index_access_method',
        'query_exec',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/commands/server_status_core',
        '$BUILD_DIR/mongo/db/ops/write_ops',
        'record_id_helpers',
        'shard_role',
    ],
)

env.Library(
    target='system_index',
    source=[
        'system_index.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/exec/scoped_timer',
        'catalog/index_key_validate',
        'catalog/multi_index_block',
        'index_builds_coordinator_interface',
        'shard_role',
    ],
)

env.Library(
    target='service_context_d',
    source=[
        'service_entry_point_mongod.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/transport/service_entry_point',
        'curop_metrics',
        'rw_concern_d',
        'storage/storage_engine_common',
        'storage/storage_engine_lock_file',
        'storage/storage_engine_metadata',
    ],
    LIBDEPS_PRIVATE=[
        'auth/auth',
        'command_can_run_here',
        'commands/fsync_locked',
        'concurrency/lock_manager',
        'not_primary_error_tracker',
        'read_concern_d_impl',
        's/sharding_runtime_d',
        'service_entry_point_common',
        'storage/storage_options',
    ],
)

env.Library(
    target='service_entry_point_common',
    source=[
        'service_entry_point_common.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/s/query_analysis_sampler',
        '$BUILD_DIR/mongo/transport/service_executor',
        'audit',
        'auth/auth',
        'auth/auth_umc',
        'auth/authprivilege',
        'auth/user_acquisition_stats',
        'command_can_run_here',
        'commands/server_status_core',
        'commands/txn_cmd_request',
        'curop_metrics',
        'initialize_api_parameters',
        'introspect',
        'multitenancy',
        'not_primary_error_tracker',
        'ops/write_ops_exec',
        'query_exec',
        'repl/repl_server_parameters',
        'repl/replica_set_messages',
        'repl/tenant_migration_access_blocker',
        'rw_concern_d',
        'server_feature_flags',
        'session/session_catalog_mongod',
        'shard_role_api',
        'shared_request_handling',
        'stats/api_version_metrics',
        'stats/counters',
        'stats/read_preference_metrics',
        'stats/resource_consumption_metrics',
        'stats/server_read_concern_write_concern_metrics',
        'stats/top',
        'storage/storage_engine_lock_file',
        'storage/storage_engine_metadata',
        'transaction/transaction',
        'write_block_bypass',
    ],
)

env.Library(
    target='resumable_index_builds_idl',
    source=[
        'resumable_index_builds.idl',
    ],
    LIBDEPS=[
        "$BUILD_DIR/mongo/base",
        '$BUILD_DIR/mongo/idl/idl_parser',
    ],
    LIBDEPS_PRIVATE=[
        'sorter/sorter_idl',
    ],
)

env.Library(
    target='index_builds_coordinator_mongod',
    source=[
        'index_builds_coordinator_mongod.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/util/concurrency/thread_pool',
        'index_builds_coordinator_interface',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/executor/task_executor_interface',
        'catalog/collection_catalog',
        'catalog/index_build_entry_idl',
        'index_build_entry_helpers',
        'repl/tenant_migration_access_blocker',
        'resumable_index_builds_idl',
        's/forwardable_operation_metadata',
        'shard_role',
        'storage/two_phase_index_build_knobs_idl',
    ],
)

env.Library(
    target='index_builds_coordinator_interface',
    source=[
        'index_builds_coordinator.cpp',
        'repl_index_build_state.cpp',
        'active_index_builds.cpp',
    ],
    LIBDEPS=[
        'catalog/commit_quorum_options',
        'catalog/index_builds_manager',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/executor/task_executor_interface',
        '$BUILD_DIR/mongo/util/fail_point',
        'catalog/collection_catalog',
        'catalog/index_build_entry_idl',
        'catalog/index_build_oplog_entry',
        'catalog/multi_index_block',
        'concurrency/exception_util',
        'concurrency/lock_manager',
        'dbhelpers',
        'index_build_entry_helpers',
        'repl/cloner_utils',
        'repl/repl_coordinator_interface',
        'repl/replica_set_messages',
        'repl/tenant_migration_access_blocker',
        'repl/timestamp_block',
        'resumable_index_builds_idl',
        'server_base',
        'shard_role',
        'storage/encryption_hooks',
        'storage/storage_util',
        'storage/two_phase_index_build_knobs_idl',
    ],
)

env.Library(
    target='index_build_entry_helpers',
    source=[
        'index_build_entry_helpers.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/catalog/commit_quorum_options',
        '$BUILD_DIR/mongo/db/catalog/index_build_entry_idl',
        '$BUILD_DIR/mongo/db/catalog/local_oplog_info',
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        '$BUILD_DIR/mongo/db/storage/write_unit_of_work',
        'dbhelpers',
        'server_base',
        'service_context',
        'shard_role',
    ],
)

env.Library(
    target='cloner',
    source=[
        'cloner.cpp',
        'cloner.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/client/authentication',
        'catalog/collection_crud',
        'catalog/collection_options',
        'catalog/multi_index_block',
        'commands/list_collections_filter',
        'concurrency/exception_util',
        'dbdirectclient',
        'index_builds_coordinator_interface',
        'multitenancy',
        'ops/write_ops',
        'repl/isself',
        'server_base',
        'shard_role',
    ],
)

env.Library(
    target="curop_metrics",
    source=[
        "curop_metrics.cpp",
    ],
    LIBDEPS_PRIVATE=[
        "$BUILD_DIR/mongo/db/query/query_stats/query_stats",
        "commands/server_status_core",
    ],
)

env.Library(
    target="introspect",
    source=[
        "introspect.cpp",
    ],
    LIBDEPS_PRIVATE=[
        "$BUILD_DIR/mongo/db/catalog/collection_crud",
        "$BUILD_DIR/mongo/db/catalog/collection_options",
        "$BUILD_DIR/mongo/db/concurrency/exception_util",
        "$BUILD_DIR/mongo/db/stats/resource_consumption_metrics",
        "shard_role",
    ],
)

env.Library(
    target='rw_concern_d',
    source=[
        'read_concern.cpp',
        'write_concern.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/query/query_stats/query_stats',
        'read_write_concern_defaults',
        'repl/read_concern_args',
        'repl/speculative_majority_read_info',
        'stats/timer_stats',
        'storage/storage_options',
    ],
    LIBDEPS_PRIVATE=[
        'commands/server_status_core',
        'concurrency/lock_manager',
        'repl/repl_coordinator_interface',
        'repl/repl_server_parameters',
        'shared_request_handling',
        'storage/storage_control',
    ],
)

env.Library(
    target='read_concern_d_impl',
    source=[
        'read_concern_mongod.cpp',
        'read_concern_mongod.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/s/grid',
        'concurrency/exception_util',
        'repl/repl_coordinator_interface',
        'repl/speculative_majority_read_info',
        'repl/tenant_migration_access_blocker',
        'server_base',
        'shard_role',
    ],
)

env.Library(
    target='rebuild_indexes',
    source=[
        'rebuild_indexes.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'catalog/index_key_validate',
        'index_builds_coordinator_interface',
        'server_base',
        'storage/write_unit_of_work',
    ],
)

env.Library(
    target='ttl_d',
    source=[
        'ttl.cpp',
        'ttl.idl',
    ],
    LIBDEPS_PRIVATE=[
        'catalog/catalog_helpers',
        'catalog/index_key_validate',
        'commands/fsync_locked',
        'commands/server_status_core',
        'ops/write_ops',
        'query_exec',
        'record_id_helpers',
        'repl/replica_set_aware_service',
        'repl/tenant_migration_access_blocker',
        's/sharding_runtime_d',
        'server_base',
        'service_context',
        'shard_role',
        'ttl_collection_cache',
    ],
)

env.Library(
    target='record_id_helpers',
    source=[
        'record_id_helpers.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/bson/bson_validate',
        '$BUILD_DIR/mongo/db/catalog/clustered_collection_options',
        '$BUILD_DIR/mongo/db/query/collation/collator_interface',
        '$BUILD_DIR/mongo/db/storage/key_string',
    ],
)

env.Library(
    target='shard_filterer',
    source=[
        'exec/shard_filterer_impl.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'exec/working_set',
        'shard_role_api',
    ],
)

env.Library(
    target='working_set_common',
    source=[
        'exec/working_set_common.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/health_log_interface',
        '$BUILD_DIR/mongo/db/exec/working_set',
        '$BUILD_DIR/mongo/db/index/index_access_method',
        '$BUILD_DIR/mongo/db/storage/execution_context',
        'server_base',
    ],
)

env.Library(
    target='write_stage_common',
    source=[
        'exec/write_stage_common.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/exec/document_value/document_value',
        '$BUILD_DIR/mongo/db/exec/working_set',
        'server_base',
        'shard_filterer',
        'shard_role_api',
        'working_set_common',
    ],
)

env.Library(
    target='query_exec',
    source=[
        'clientcursor.cpp',
        'cursor_manager.cpp',
        'exec/and_hash.cpp',
        'exec/and_sorted.cpp',
        'exec/batched_delete_stage.cpp',
        'exec/batched_delete_stage.idl',
        'exec/batched_delete_stage_buffer.cpp',
        'exec/cached_plan.cpp',
        'exec/collection_scan.cpp',
        'exec/count.cpp',
        'exec/count_scan.cpp',
        'exec/delete_stage.cpp',
        'exec/disk_use_options.idl',
        'exec/distinct_scan.cpp',
        'exec/eof.cpp',
        'exec/fetch.cpp',
        'exec/geo_near.cpp',
        'exec/idhack.cpp',
        'exec/index_scan.cpp',
        'exec/limit.cpp',
        'exec/merge_sort.cpp',
        'exec/mock_stage.cpp',
        'exec/multi_iterator.cpp',
        'exec/multi_plan.cpp',
        'exec/near.cpp',
        'exec/or.cpp',
        'exec/plan_cache_util.cpp',
        'exec/plan_stage.cpp',
        'exec/projection.cpp',
        'exec/queued_data_stage.cpp',
        'exec/record_store_fast_count.cpp',
        'exec/requires_collection_stage.cpp',
        'exec/requires_index_stage.cpp',
        'exec/return_key.cpp',
        'exec/sample_from_timeseries_bucket.cpp',
        'exec/shard_filter.cpp',
        'exec/skip.cpp',
        'exec/sort.cpp',
        'exec/sort_key_generator.cpp',
        'exec/spool.cpp',
        'exec/subplan.cpp',
        'exec/text_match.cpp',
        'exec/text_or.cpp',
        'exec/timeseries_modify.cpp',
        'exec/trial_period_utils.cpp',
        'exec/trial_stage.cpp',
        'exec/unpack_timeseries_bucket.cpp',
        'exec/update_stage.cpp',
        'exec/upsert_stage.cpp',
        'ops/delete_request.idl',
        'ops/parsed_delete.cpp',
        'ops/update_result.cpp',
        'pipeline/document_source_cursor.cpp',
        'pipeline/document_source_geo_near_cursor.cpp',
        'pipeline/inner_pipeline_stage_impl.cpp',
        'pipeline/pipeline_d.cpp',
        'pipeline/plan_executor_pipeline.cpp',
        'pipeline/plan_explainer_pipeline.cpp',
        'query/all_indices_required_checker.cpp',
        'query/bind_input_params.cpp',
        'query/classic_stage_builder.cpp',
        'query/cost_model/on_coefficients_change_updater_impl.cpp',
        'query/cqf_command_utils.cpp',
        'query/cqf_get_executor.cpp',
        'query/explain.cpp',
        'query/find.cpp',
        'query/get_executor.cpp',
        'query/internal_plans.cpp',
        'query/plan_executor.cpp',
        'query/plan_executor_factory.cpp',
        'query/plan_executor_impl.cpp',
        'query/plan_executor_sbe.cpp',
        'query/plan_explainer_factory.cpp',
        'query/plan_explainer_impl.cpp',
        'query/plan_explainer_sbe.cpp',
        'query/plan_insert_listener.cpp',
        'query/plan_ranker.cpp',
        'query/plan_yield_policy_impl.cpp',
        'query/plan_yield_policy_sbe.cpp',
        'query/query_utils.cpp',
        'query/sbe_cached_solution_planner.cpp',
        'query/sbe_multi_planner.cpp',
        'query/sbe_plan_ranker.cpp',
        'query/sbe_runtime_planner.cpp',
        'query/sbe_stage_builder.cpp',
        'query/sbe_stage_builder_accumulator.cpp',
        'query/sbe_stage_builder_coll_scan.cpp',
        'query/sbe_stage_builder_const_eval.cpp',
        'query/sbe_stage_builder_eval_frame.cpp',
        'query/sbe_stage_builder_expression.cpp',
        'query/sbe_stage_builder_filter.cpp',
        'query/sbe_stage_builder_abt_helpers.cpp',
        'query/sbe_stage_builder_abt_holder_impl.cpp',
        'query/sbe_stage_builder_helpers.cpp',
        'query/sbe_stage_builder_index_scan.cpp',
        'query/sbe_stage_builder_lookup.cpp',
        'query/sbe_stage_builder_projection.cpp',
        'query/sbe_stage_builder_type_checker.cpp',
        'query/sbe_sub_planner.cpp',
        'query/shard_filterer_factory_impl.cpp',
        'query/stage_builder_util.cpp',
        'query/wildcard_multikey_paths.cpp',
        'query/yield_policy_callbacks_impl.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/auth/auth_checks',
        '$BUILD_DIR/mongo/scripting/scripting',
        '$BUILD_DIR/mongo/util/background_job',
        '$BUILD_DIR/mongo/util/elapsed_tracker',
        '$BUILD_DIR/third_party/s2/s2',
        'audit',
        'bson/dotted_path_support',
        'catalog/collection_query_info',
        'catalog/index_catalog',
        'catalog/index_catalog_entry',
        'commands',
        'curop_failpoint_helpers',
        'cursor_server_params',
        'dbdirectclient',
        'exec/projection_executor',
        'exec/sbe/query_sbe_stages',
        'exec/sbe/query_sbe_storage',
        'exec/scoped_timer',
        'exec/sort_executor',
        'exec/working_set',
        'fts/base_fts',
        'index/index_access_method',
        'matcher/expressions_mongod_only',
        'ops/parsed_update',
        'pipeline/pipeline',
        'query/cost_model/query_cost_model',
        'query/plan_yield_policy',
        'query/query_common',
        'query/query_plan_cache',
        'query/query_planner',
        'repl/repl_coordinator_interface',
        'session/logical_session_cache',
        'shard_filterer',
        'shard_role',
        'shared_request_handling',
        'stats/latency_server_stats',
        'stats/serveronly_stats',
        'storage/remove_saver',
        'storage/storage_options',
        'update/update_driver',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/catalog/database_holder',
        '$BUILD_DIR/mongo/db/catalog/health_log_interface',
        '$BUILD_DIR/mongo/db/catalog/local_oplog_info',
        '$BUILD_DIR/mongo/db/commands/server_status_core',
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        '$BUILD_DIR/mongo/db/exec/sbe/query_sbe_abt',
        '$BUILD_DIR/mongo/db/internal_transactions_feature_flag',
        '$BUILD_DIR/mongo/db/pipeline/abt_translation',
        '$BUILD_DIR/mongo/db/pipeline/change_stream_pipeline',
        '$BUILD_DIR/mongo/db/pipeline/document_source_internal_apply_oplog_update',
        '$BUILD_DIR/mongo/db/pipeline/pipeline_visitor',
        '$BUILD_DIR/mongo/db/query/ce/query_ce_heuristic',
        '$BUILD_DIR/mongo/db/query/ce/query_ce_histogram',
        '$BUILD_DIR/mongo/db/query/ce/query_ce_sampling',
        '$BUILD_DIR/mongo/db/query/optimizer/optimizer',
        '$BUILD_DIR/mongo/db/repl/wait_for_majority_service',
        '$BUILD_DIR/mongo/db/session/kill_sessions',
        '$BUILD_DIR/mongo/db/sorter/sorter_stats',
        '$BUILD_DIR/mongo/db/stats/resource_consumption_metrics',
        '$BUILD_DIR/mongo/db/storage/record_store_base',
        '$BUILD_DIR/mongo/db/timeseries/timeseries_options',
        '$BUILD_DIR/mongo/db/timeseries/timeseries_write_util',
        'not_primary_error_tracker',
        'record_id_helpers',
        'timeseries/timeseries_conversion_util',
        'working_set_common',
        'write_stage_common',
    ],
)

env.Library(
    target='query_expressions',
    source=[
        'matcher/doc_validation_error.cpp',
        'matcher/doc_validation_util.cpp',
        'matcher/expression.cpp',
        'matcher/expression_algo.cpp',
        'matcher/expression_array.cpp',
        'matcher/expression_expr.cpp',
        'matcher/expression_geo.cpp',
        'matcher/expression_geo_serializer.cpp',
        'matcher/expression_internal_bucket_geo_within.cpp',
        'matcher/expression_leaf.cpp',
        'matcher/expression_parameterization.cpp',
        'matcher/expression_parser.cpp',
        'matcher/expression_text_base.cpp',
        'matcher/expression_text_noop.cpp',
        'matcher/expression_tree.cpp',
        'matcher/expression_where_base.cpp',
        'matcher/expression_where_noop.cpp',
        'matcher/expression_with_placeholder.cpp',
        'matcher/extensions_callback.cpp',
        'matcher/extensions_callback_noop.cpp',
        'matcher/implicit_validator.cpp',
        'matcher/match_details.cpp',
        'matcher/match_expression_dependencies.cpp',
        'matcher/match_expression_util.cpp',
        'matcher/matchable.cpp',
        'matcher/matcher.cpp',
        'matcher/matcher_type_set.cpp',
        'matcher/rewrite_expr.cpp',
        'matcher/schema/encrypt_schema.idl',
        'matcher/schema/encrypt_schema_types.cpp',
        'matcher/schema/expression_internal_schema_all_elem_match_from_index.cpp',
        'matcher/schema/expression_internal_schema_allowed_properties.cpp',
        'matcher/schema/expression_internal_schema_cond.cpp',
        'matcher/schema/expression_internal_schema_eq.cpp',
        'matcher/schema/expression_internal_schema_fmod.cpp',
        'matcher/schema/expression_internal_schema_match_array_index.cpp',
        'matcher/schema/expression_internal_schema_num_array_items.cpp',
        'matcher/schema/expression_internal_schema_num_properties.cpp',
        'matcher/schema/expression_internal_schema_object_match.cpp',
        'matcher/schema/expression_internal_schema_root_doc_eq.cpp',
        'matcher/schema/expression_internal_schema_str_length.cpp',
        'matcher/schema/expression_internal_schema_unique_items.cpp',
        'matcher/schema/expression_internal_schema_xor.cpp',
        'matcher/schema/json_pointer.cpp',
        'matcher/schema/json_schema_parser.cpp',
        'pipeline/expression.cpp',
        'pipeline/expression_context.cpp',
        'pipeline/expression_dependencies.cpp',
        'pipeline/expression_function.cpp',
        'pipeline/expression_js_emit.cpp',
        'pipeline/expression_parser.idl',
        'pipeline/expression_test_api_version.cpp',
        'pipeline/expression_trigonometric.cpp',
        'pipeline/javascript_execution.cpp',
        'pipeline/make_js_function.cpp',
        'pipeline/monotonic_expression.cpp',
        'pipeline/variables.cpp',
        'query/query_shape/cmd_with_let_shape.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
        '$BUILD_DIR/mongo/crypto/fle_crypto',
        '$BUILD_DIR/mongo/scripting/scripting',
        '$BUILD_DIR/mongo/scripting/scripting_common',
        '$BUILD_DIR/mongo/util/intrusive_counter',
        '$BUILD_DIR/mongo/util/pcre_util',
        '$BUILD_DIR/mongo/util/pcre_wrapper',
        '$BUILD_DIR/mongo/util/summation',
        'bson/dotted_path_support',
        'commands/test_commands_enabled',
        'common',
        'exec/document_value/document_value',
        'fts/fts_query_noop',
        'geo/geometry',
        'geo/geoparser',
        'matcher/path',
        'pipeline/aggregation_request_helper',
        'pipeline/dependencies',
        'pipeline/variable_validation',
        'query/collation/collator_factory_interface',
        'query/collation/collator_interface',
        'query/datetime/date_time_support',
        'query/query_knobs',
        'query/query_shape/query_shape_common',
        'stats/counters',
        'update/pattern_cmp',
    ],
    LIBDEPS_PRIVATE=[
        'mongohasher',
        'server_base',
        'service_context',
        'vector_clock',
    ],
)

env.Library(
    target='startup_recovery',
    source=[
        'repair.cpp',
        'startup_recovery.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'catalog/catalog_helpers',
        'catalog/collection_catalog',
        'catalog/collection_crud',
        'catalog/collection_validation',
        'catalog/database_holder',
        'catalog/document_validation',
        'catalog/index_key_validate',
        'catalog/multi_index_block',
        'commands/mongod_fcv',
        'concurrency/exception_util',
        'dbdirectclient',
        'dbhelpers',
        'index_builds_coordinator_interface',
        'multitenancy',
        'rebuild_indexes',
        'repl/oplog',
        'repl/repl_settings',
        'rw_concern_d',
        'server_feature_flags',
        'storage/storage_repair_observer',
        'storage/storage_util',
        'timeseries/timeseries_extended_range',
        'vector_clock',
    ],
)

env.Library(
    target='service_liaison',
    source=[
        'service_liaison.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/crypto/sha1_block',
        'keys_collection_document',
        'vector_clock',
    ],
)

envWithAsio = env.Clone()
envWithAsio.InjectThirdParty(libraries=['asio'])

envWithAsio.Library(
    target='service_liaison_mock',
    source=[
        'service_liaison_mock.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/session/kill_sessions',
        '$BUILD_DIR/mongo/util/periodic_runner_factory',
        'service_liaison',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/executor/async_timer_mock',
    ],
)

envWithAsio.Library(
    target='service_liaison_mongod',
    source=[
        'service_liaison_mongod.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/periodic_runner',
        'query_exec',
        'service_context',
        'service_liaison',
    ],
)

env.Library(
    target='service_liaison_mongos',
    source=[
        'service_liaison_mongos.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        '$BUILD_DIR/mongo/s/grid',
        '$BUILD_DIR/mongo/s/query/cluster_cursor_manager',
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/periodic_runner',
        'service_context',
        'service_liaison',
    ],
)

env.Library(
    target='index_commands_idl',
    source=[
        'create_indexes.idl',
        'drop_indexes.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/authprivilege',
        '$BUILD_DIR/mongo/db/catalog/commit_quorum_options',
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        'server_base',
    ],
)

env.Library(
    target='error_labels',
    source=[
        'error_labels.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/pipeline/lite_parsed_document_source',
        '$BUILD_DIR/mongo/db/query/query_stats/query_stats',
        '$BUILD_DIR/mongo/db/session/logical_session_id',
        'commands',
    ],
)

env.Library(
    target='shared_request_handling',
    source=[
        'transaction_validation.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        'api_parameters',
        'error_labels',
        'session/logical_session_cache_impl',
    ],
)

env.Library(
    target='api_parameters',
    source=[
        'api_parameters.cpp',
        'api_parameters.idl',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
    ],
)

env.Library(
    target='initialize_api_parameters',
    source=[
        'initialize_api_parameters.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        'api_parameters',
        'commands',
    ],
)

env.Library(
    target='operation_time_tracker',
    source=[
        'operation_time_tracker.cpp',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
        'service_context',
    ],
)

env.Library(
    target='operation_killer',
    source=[
        'operation_killer.cpp',
    ],
    LIBDEPS=[
        'service_context',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/auth',
        '$BUILD_DIR/mongo/db/auth/authprivilege',
        'server_base',
    ],
)

env.Library(
    target='periodic_runner_job_abort_expired_transactions',
    source=[
        'periodic_runner_job_abort_expired_transactions.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/session/kill_sessions_local',
        '$BUILD_DIR/mongo/db/transaction/transaction',
        '$BUILD_DIR/mongo/util/periodic_runner',
    ],
)

env.Library(
    target='snapshot_window_options',
    source=[
        'snapshot_window_options.idl',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
    ],
)

env.Library(
    target='signed_logical_time',
    source=[
        'signed_logical_time.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/crypto/sha1_block',
        'server_base',
    ],
)

env.Library(
    target='rs_local_client',
    source=[
        'rs_local_client.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
        'dbdirectclient',
        'rw_concern_d',
    ],
)

env.Library(
    target='keys_collection_document',
    source=[
        'keys_collection_document.idl',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
    ],
)

env.Library(
    target='keys_collection_util',
    source=[
        'keys_collection_util.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/concurrency/exception_util',
        'dbhelpers',
        'keys_collection_document',
        'shard_role',
    ],
)

env.Library(
    target='keys_collection_client_direct',
    source=[
        'keys_collection_client_direct.cpp',
    ],
    LIBDEPS=[
        'keys_collection_document',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/s/catalog/sharding_catalog_client',
        '$BUILD_DIR/mongo/s/client/shard_interface',
        'rs_local_client',
        'server_base',
    ],
)

env.Library(
    target='keys_collection_client_sharded',
    source=[
        'keys_collection_client_sharded.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/s/catalog/sharding_catalog_client',
        'keys_collection_document',
        'server_base',
    ],
)

env.Library(
    target='vector_clock',
    source=[
        'key_generator.cpp',
        'keys_collection_cache.cpp',
        'keys_collection_manager.cpp',
        'keys_collection_manager.idl',
        'logical_time_validator.cpp',
        'time_proof_service.cpp',
        'vector_clock.cpp',
        'vector_clock.idl',
        'vector_clock_document.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/transport/transport_layer_common',
        'auth/auth',
        'auth/authprivilege',
        'global_settings',
        'keys_collection_client_sharded',
        'keys_collection_document',
        'repl/repl_coordinator_interface',
        'signed_logical_time',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/crypto/sha_block_${MONGO_CRYPTO}',
        'server_base',
        'service_context',
    ],
)

env.Library(
    target='vector_clock_mutable',
    source=[
        'vector_clock_mutable.cpp',
    ],
    LIBDEPS=[
        'vector_clock',
    ],
)

env.Library(
    target='vector_clock_mongod',
    source=[
        's/topology_time_ticker.cpp',
        'vector_clock_mongod.cpp',
    ],
    LIBDEPS=[
        'vector_clock_mutable',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/s/grid',
        'dbdirectclient',
        'repl/replica_set_aware_service',
        'rw_concern_d',
        'server_base',
    ],
)

env.Library(
    target='vector_clock_trivial',
    source=[
        'vector_clock_trivial.cpp',
    ],
    LIBDEPS=[
        'vector_clock_mutable',
    ],
)

env.Library(
    target='logical_time_metadata_hook',
    source=[
        'vector_clock_metadata_hook.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/rpc/metadata',
        'operation_time_tracker',
        'vector_clock',
    ],
)

env.Library(
    target='client_metadata_propagation_egress_hook',
    source=[
        'client_metadata_propagation_egress_hook.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/rpc/client_metadata',
        '$BUILD_DIR/mongo/rpc/metadata',
        '$BUILD_DIR/mongo/rpc/metadata_impersonated_user',
        'server_base',
        'server_feature_flags',
    ],
)

env.Library(
    target='vector_clock_test_fixture',
    source=[
        'vector_clock_test_fixture.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/util/clock_source_mock',
        's/sharding_mongod_test_fixture',
        'signed_logical_time',
        'vector_clock',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/op_observer/oplog_writer_impl',
    ],
)

env.Library(
    target='feature_compatibility_version_metrics',
    source=[
        'feature_compatibility_version_metrics.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/server_status_core',
        'server_base',
    ],
)

env.Library(
    target='service_context_test_fixture',
    source=[
        'service_context_test_fixture.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/client/clientdriver_network',
        '$BUILD_DIR/mongo/unittest/unittest',
        'service_context',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/op_observer/op_observer',
        '$BUILD_DIR/mongo/util/clock_source_mock',
    ],
)

env.Library(
    target='service_context_d_test_fixture',
    source=[
        'service_context_d_test_fixture.cpp',
    ],
    LIBDEPS=[
        'service_context_test_fixture',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/clock_source_mock',
        'auth/auth_impl_internal',
        'catalog/catalog_impl',
        'catalog/database_holder',
        'commands/mongod',
        'index/index_access_method',
        'index_builds_coordinator_mongod',
        's/sharding_runtime_d',
        'service_context_d',
        'storage/devnull/storage_devnull',
        'storage/storage_control',
        'storage/storage_options',
        'storage/wiredtiger/storage_wiredtiger',
    ],
)

env.Library(
    target='service_context_devnull_test_fixture',
    source=[
        'service_context_devnull_test_fixture.cpp',
    ],
    LIBDEPS=[
        'service_context_d_test_fixture',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/auth/authmocks',
        '$BUILD_DIR/mongo/db/storage/devnull/storage_devnull',
    ],
)

env.Library(
    target='log_process_details',
    source=[
        'log_process_details.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/util/net/network',
        'repl/repl_coordinator_interface',
        'repl/replica_set_messages',
        'server_options_servers',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/processinfo',
    ],
)

env.Library(
    target='cursor_server_params',
    source=[
        'cursor_server_params.cpp',
        'cursor_server_params.idl',
    ],
    LIBDEPS_PRIVATE=[
        'server_base',
    ],
)

env.Library(
    target='generic_cursor',
    source=[
        'allocate_cursor_id.cpp',
        'generic_cursor.idl',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/repl/optime',
        '$BUILD_DIR/mongo/util/namespace_string_database_name_util',
        'server_base',
        'service_context',
    ],
)

env.Library(
    target='ttl_collection_cache',
    source=[
        'ttl_collection_cache.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/db/service_context',
    ],
)

env.Library(
    target='wire_version',
    source=[
        'wire_version.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/bson/util/bson_extract',
    ],
)

asioEnv = env.Clone()
asioEnv.InjectThirdParty('asio')

env.Library(
    target='traffic_recorder',
    source=[
        'traffic_recorder.cpp',
        'traffic_recorder_validators.cpp',
        'traffic_recorder.idl',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/db/commands/server_status_core',
        '$BUILD_DIR/mongo/db/service_context',
        '$BUILD_DIR/mongo/rpc/rpc',
        'server_base',
    ],
)

env.Library(
    target='traffic_reader',
    source=[
        'traffic_reader.cpp',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/rpc/message',
        '$BUILD_DIR/mongo/rpc/rpc',
    ],
)

env.Program(
    target="mongotrafficreader",
    source=[
        "traffic_reader_main.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/rpc/message',
        '$BUILD_DIR/mongo/util/signal_handlers',
        'traffic_reader',
    ],
)

env.Library(
    target="mongod_options_init",
    source=[
        "mongod_options_init.cpp",
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/util/net/ssl_options_server' if get_option('ssl') == 'on' else '',
        '$BUILD_DIR/mongo/util/options_parser/options_parser',
        'mongod_options',
    ],
)

env.Library(
    target="mongod_initializers",
    source=[
        # NOTE: If you add an additional source file here, please delete
        # the file db/mongod_initializers.cpp.
        "mongod_initializers.cpp",
    ],
    LIBDEPS_PRIVATE=[
        # NOTE: If you need to add a static or mongo initializer to mongod startup,
        # please add that library here, as a private library dependency.
        '$BUILD_DIR/mongo/executor/async_rpc_error_info',
        '$BUILD_DIR/mongo/executor/network_interface_factory',
        '$BUILD_DIR/mongo/rpc/rpc',
        '$BUILD_DIR/mongo/s/commands/sharded_cluster_sharding_commands',
        '$BUILD_DIR/mongo/scripting/scripting_server',
        '$BUILD_DIR/mongo/transport/message_compressor_options_server',
        '$BUILD_DIR/mongo/transport/service_entry_point',
        '$BUILD_DIR/mongo/transport/transport_layer_manager',
        '$BUILD_DIR/mongo/util/clock_sources',
        '$BUILD_DIR/mongo/util/elapsed_tracker',
        '$BUILD_DIR/mongo/util/fail_point',
        '$BUILD_DIR/mongo/util/latch_analyzer'
        if get_option('use-diagnostic-latches') == 'on' else [],
        '$BUILD_DIR/mongo/util/net/network',
        '$BUILD_DIR/mongo/util/ntservice',
        '$BUILD_DIR/mongo/util/options_parser/options_parser_init',
        '$BUILD_DIR/mongo/util/periodic_runner_factory',
        '$BUILD_DIR/mongo/util/pin_code_segments' if env.TargetOSIs('linux') else [],
        '$BUILD_DIR/mongo/util/testing_options',
        '$BUILD_DIR/mongo/util/version_impl',
        '$BUILD_DIR/mongo/watchdog/watchdog_mongod',
        '$BUILD_DIR/third_party/shim_snappy',
        'audit_commands' if has_option('audit') else [],
        'auth/auth_op_observer',
        'auth/authmongod',
        'bson/dotted_path_support',
        'catalog/catalog_impl',
        'catalog/collection_options',
        'catalog/document_validation',
        'catalog/health_log_interface',
        'catalog/index_key_validate',
        'client_metadata_propagation_egress_hook',
        'collection_index_usage_tracker',
        'commands/mongod',
        'commands/mongod_fcv',
        'commands/server_status_servers',
        'common',
        'concurrency/flow_control_ticketholder',
        'concurrency/lock_manager',
        'curop_metrics',
        'dbdirectclient',
        'dbhelpers',
        'exec/working_set',
        'feature_compatibility_version_metrics',
        'ftdc/ftdc_mongod',
        'fts/ftsmongod',
        'index/index_access_method',
        'index_builds_coordinator_mongod',
        'introspect',
        'keys_collection_client_direct',
        'logical_time_metadata_hook',
        'matcher/expressions_mongod_only',
        'mirror_maestro',
        'mongod_options',
        'mongod_options_init',
        'periodic_runner_job_abort_expired_transactions',
        'pipeline/aggregation',
        'pipeline/pipeline_mongod',
        'pipeline/process_interface/mongod_process_interface_factory',
        'query_exec',
        'read_concern_d_impl',
        'read_write_concern_defaults',
        'repl/oplog_application',
        'repl/oplog_buffer_blocking_queue',
        'repl/oplog_buffer_collection',
        'repl/oplog_buffer_proxy',
        'repl/repl_coordinator_impl',
        'repl/repl_set_commands',
        'repl/repl_settings',
        'repl/replica_set_aware_service',
        'repl/rs_rollback',
        'repl/serveronly_repl',
        'repl/storage_interface_impl',
        'repl/topology_coordinator',
        'rw_concern_d',
        'serverless/shard_split_commands',
        'service_liaison_mongod',
        'session/kill_sessions_local',
        'session/logical_session_cache_impl',
        'session/sessions_collection_rs',
        'session/sessions_collection_standalone',
        'shard_role',
        'startup_warnings_mongod',
        'stats/change_collection_server_status',
        'stats/counters',
        'stats/latency_server_stats',
        'stats/serveronly_stats',
        'stats/top',
        'storage/backup_cursor_hooks',
        'storage/devnull/storage_devnull',
        'storage/encryption_hooks',
        'storage/flow_control',
        'storage/flow_control_parameters',
        'storage/inmemory/storage_inmemory' if inmemory else [],
        'storage/storage_control',
        'storage/storage_engine_lock_file',
        'storage/storage_engine_metadata',
        'storage/storage_init_d',
        'storage/storage_options',
        'system_index',
        'traffic_recorder',
        'ttl_collection_cache',
        'ttl_d',
        'update/update_driver',
        'update_index_data',
        'windows_options' if env.TargetOSIs('windows') else [],
    ],
    LIBDEPS=[
        # NOTE: This list must remain empty. Please only add to LIBDEPS_PRIVATE
    ],
)

env.Library(
    target='mongod_main',
    source=[
        'mongod_main.cpp',
        'logical_session_cache_factory_mongod.cpp',
        'read_write_concern_defaults_cache_lookup_mongod.cpp',
    ],
    LIBDEPS_PRIVATE=[
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongod,
        # please add that library as a private libdep of
        # mongod_initializers.
        '$BUILD_DIR/mongo/client/clientdriver_minimal',
        '$BUILD_DIR/mongo/db/catalog/collection_crud',
        '$BUILD_DIR/mongo/db/change_collection_expired_change_remover',
        '$BUILD_DIR/mongo/db/change_stream_change_collection_manager',
        '$BUILD_DIR/mongo/db/change_stream_options_manager',
        '$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
        '$BUILD_DIR/mongo/db/pipeline/change_stream_expired_pre_image_remover',
        '$BUILD_DIR/mongo/db/s/query_analysis_writer',
        '$BUILD_DIR/mongo/db/set_change_stream_state_coordinator',
        '$BUILD_DIR/mongo/db/telemetry/telemetry_d',
        '$BUILD_DIR/mongo/idl/cluster_server_parameter',
        '$BUILD_DIR/mongo/idl/cluster_server_parameter_initializer',
        '$BUILD_DIR/mongo/idl/cluster_server_parameter_op_observer',
        '$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl',
        '$BUILD_DIR/mongo/s/grid',
        '$BUILD_DIR/mongo/s/sessions_collection_sharded',
        '$BUILD_DIR/mongo/scripting/scripting',
        '$BUILD_DIR/mongo/transport/ingress_handshake_metrics',
        '$BUILD_DIR/mongo/transport/service_entry_point',
        '$BUILD_DIR/mongo/transport/transport_layer_manager',
        '$BUILD_DIR/mongo/util/cmdline_utils/cmdline_utils',
        '$BUILD_DIR/mongo/util/concurrency/thread_pool',
        '$BUILD_DIR/mongo/util/latch_analyzer'
        if get_option('use-diagnostic-latches') == 'on' else [],
        '$BUILD_DIR/mongo/util/net/http_client_impl',
        '$BUILD_DIR/mongo/util/net/ssl_manager',
        '$BUILD_DIR/mongo/util/signal_handlers',
        '$BUILD_DIR/mongo/watchdog/watchdog_mongod',
        'auth/auth_op_observer',
        'catalog/catalog_helpers',
        'catalog/catalog_impl',
        'catalog/health_log',
        'catalog/health_log_interface',
        'commands/mongod',
        'commands/test_commands',
        'concurrency/flow_control_ticketholder',
        'concurrency/lock_manager',
        'fle_crud_mongod',
        'ftdc/ftdc_mongod',
        'index/index_access_method',
        'index_builds_coordinator_mongod',
        'keys_collection_client_direct',
        'log_process_details',
        'mirror_maestro',
        'mongod_initializers',
        'mongod_options',
        'op_observer/fcv_op_observer',
        'op_observer/op_observer',
        'op_observer/oplog_writer_impl',
        'op_observer/oplog_writer_transaction_proxy',
        'op_observer/user_write_block_mode_op_observer',
        'periodic_runner_job_abort_expired_transactions',
        'pipeline/process_interface/mongod_process_interface_factory',
        'query/stats/stats',
        'repl/drop_pending_collection_reaper',
        'repl/initial_syncer',
        'repl/repl_coordinator_impl',
        'repl/replication_recovery',
        'repl/serveronly_repl',
        'repl/shard_merge_recipient_service',
        'repl/storage_interface_impl',
        'repl/tenant_migration_donor_service',
        'repl/tenant_migration_recipient_service',
        'repl/topology_coordinator',
        'repl/wait_for_majority_service',
        's/sessions_collection_config_server',
        's/sharding_commands_d',
        's/sharding_runtime_d',
        'serverinit',
        'serverless/shard_split_donor_service',
        'service_context_d',
        'service_liaison_mongod',
        'session/kill_sessions',
        'session/kill_sessions_local',
        'session/session_catalog_mongod',
        'session/sessions_collection_rs',
        'session/sessions_collection_standalone',
        'shard_role',
        'startup_recovery',
        'startup_warnings_mongod',
        'storage/backup_cursor_hooks',
        'storage/disk_space_monitor',
        'storage/flow_control',
        'storage/flow_control_parameters',
        'storage/oplog_cap_maintainer_thread',
        'storage/storage_control',
        'storage/storage_engine_common',
        'system_index',
        'ttl_d',
        'vector_clock',
    ],
    LIBDEPS_TAGS=[
        # NOTE: This library must not link publicly. Please only add to LIBDEPS_PRIVATE
        'lint-no-public-deps',
    ],
)

if env.TargetOSIs('windows'):
    generatedDbManifest = env.Substfile(
        'mongod.manifest.in',
        SUBST_DICT=[
            ('@mongo_version_major@', version_parts[0]),
            ('@mongo_version_minor@', version_parts[1]),
            ('@mongo_version_patch@', version_parts[2]),
            ('@mongo_version_extra@', version_parts[3]),
            ('@mongo_version_extra_str@', version_extra),
        ],
    )

    env.Alias('generated-sources', generatedDbManifest)
    env.Depends("mongod.res", generatedDbManifest)

# Do not discard encryption extension's entry point
env.Append( LINKFLAGS=["-upercona_encryption_extension_init"] );

env.Program(
    target="mongod",
    source=['mongod.cpp'] + env.WindowsResourceFile("mongod.rc"),
    LIBDEPS=[
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongod,
        # please add that library as a private libdep of
        # mongod_initializers.
        '$BUILD_DIR/mongo/base',
        'mongod_main',
    ],
    AIB_COMPONENT="mongod",
    AIB_COMPONENTS_EXTRA=[
        "core",
        "default",
        "devcore",
        "dist",
        "dist-test",
        "integration-tests",
        "serverless",
        "serverless-test",
        "servers",
    ],
)

env.Library(
    target='op_msg_fuzzer_fixture',
    source=[
        'op_msg_fuzzer_fixture.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/transport/transport_layer_mock',
    ],
    LIBDEPS_PRIVATE=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/rpc/rpc',
        '$BUILD_DIR/mongo/unittest/unittest',
        '$BUILD_DIR/mongo/util/periodic_runner_factory',
        'auth/auth',
        'auth/authmocks',
        'catalog/catalog_impl',
        'catalog/database_holder',
        'op_observer/op_observer',
        'repl/replmocks',
        'service_context_d',
        'shard_role_api',
        'storage/storage_control',
        'storage/storage_options',
        'storage/wiredtiger/storage_wiredtiger',
    ],
)

# TODO(SERVER-45266) This could be part of db_unittest_test but it needs to mutate
# storageGlobalParams.
env.CppUnitTest(
    target='op_msg_fuzzer_fixture_test',
    source=[
        'op_msg_fuzzer_fixture_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        '$BUILD_DIR/mongo/rpc/rpc',
        'op_msg_fuzzer_fixture',
    ],
)

envWithAsio = env.Clone()
envWithAsio.InjectThirdParty(libraries=['asio'])

if wiredtiger:
    envWithAsio.CppUnitTest(
        target='db_unittest_test',
        source=[
            'bulk_write_shard_test.cpp',
            'cancelable_operation_context_test.cpp',
            'catalog_raii_test.cpp',
            'change_collection_expired_change_remover_test.cpp',
            'client_context_test.cpp',
            'client_strand_test.cpp',
            'collection_index_usage_tracker_test.cpp',
            'commands_test_example.idl',
            'commands_test.cpp',
            'curop_test.cpp',
            'database_name_test.cpp',
            'db_raii_multi_collection_test.cpp',
            'db_raii_test.cpp',
            'dbdirectclient_test.cpp',
            'dbmessage_test.cpp',
            'error_labels_test.cpp',
            'explain_test.cpp',
            'field_parser_test.cpp',
            'field_ref_set_test.cpp',
            'field_ref_test.cpp',
            'fle_crud_test.cpp',
            'global_index_test.cpp',
            'hasher_test.cpp',
            'index_build_entry_helpers_test.cpp',
            'index_builds_coordinator_mongod_test.cpp',
            'index_builds_coordinator_test.cpp',
            'keypattern_test.cpp',
            'keys_collection_document_test.cpp',
            'logical_time_test.cpp',
            'mirroring_sampler_test.cpp',
            'multi_key_path_tracker_test.cpp',
            'namespace_string_test.cpp',
            'operation_context_test.cpp',
            'operation_cpu_timer_test.cpp',
            'operation_id_test.cpp',
            'operation_time_tracker_test.cpp',
            'persistent_task_store_test.cpp',
            'query/fle/equality_predicate_test.cpp',
            'query/fle/range_predicate_test.cpp',
            'query/fle/range_validator_test.cpp',
            'query/fle/query_rewriter_test.cpp',
            'read_write_concern_defaults_test.cpp',
            'read_write_concern_provenance_test.cpp',
            'record_id_test.cpp',
            'server_options_test.cpp',
            'session/internal_session_pool_test.cpp',
            'session/internal_transactions_reap_service_test.cpp',
            'session/logical_session_cache_test.cpp',
            'session/logical_session_id_test.cpp',
            'session/session_catalog_mongod_test.cpp',
            'session/session_catalog_test.cpp',
            'shard_id_test.cpp',
            'startup_warnings_mongod_test.cpp',
            'thread_client_test.cpp',
            'time_proof_service_test.cpp',
            'ttl_collection_cache_test.cpp',
            'ttl_test.cpp',
            'update_index_data_test.cpp',
            'vector_clock_mongod_test.cpp',
            'vector_clock_test.cpp',
            'wire_version_test.cpp',
            'write_concern_options_test.cpp',
        ],
        LIBDEPS=[
            '$BUILD_DIR/mongo/bson/util/bson_extract',
            '$BUILD_DIR/mongo/client/read_preference',
            '$BUILD_DIR/mongo/crypto/aead_encryption',
            '$BUILD_DIR/mongo/crypto/encrypted_field_config',
            '$BUILD_DIR/mongo/crypto/fle_crypto',
            '$BUILD_DIR/mongo/db/auth/auth',
            '$BUILD_DIR/mongo/db/auth/authmocks',
            '$BUILD_DIR/mongo/db/auth/security_token',
            '$BUILD_DIR/mongo/db/catalog/catalog_test_fixture',
            '$BUILD_DIR/mongo/db/catalog/collection_crud',
            '$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info',
            '$BUILD_DIR/mongo/db/catalog/database_holder',
            '$BUILD_DIR/mongo/db/catalog/index_build_entry_idl',
            '$BUILD_DIR/mongo/db/change_collection_expired_change_remover',
            '$BUILD_DIR/mongo/db/change_stream_change_collection_manager',
            '$BUILD_DIR/mongo/db/change_stream_serverless_helpers',
            '$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
            '$BUILD_DIR/mongo/db/commands/bulk_write_command',
            '$BUILD_DIR/mongo/db/mongohasher',
            '$BUILD_DIR/mongo/db/ops/write_ops',
            '$BUILD_DIR/mongo/db/pipeline/change_stream_expired_pre_image_remover',
            '$BUILD_DIR/mongo/db/query/common_query_enums_and_helpers',
            '$BUILD_DIR/mongo/db/query/query_test_service_context',
            '$BUILD_DIR/mongo/db/repl/image_collection_entry',
            '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
            '$BUILD_DIR/mongo/db/repl/repl_server_parameters',
            '$BUILD_DIR/mongo/db/repl/replica_set_aware_service',
            '$BUILD_DIR/mongo/db/repl/replmocks',
            '$BUILD_DIR/mongo/db/repl/storage_interface_impl',
            '$BUILD_DIR/mongo/db/repl/tenant_migration_access_blocker',
            '$BUILD_DIR/mongo/db/s/shard_server_test_fixture',
            '$BUILD_DIR/mongo/db/session/logical_session_cache',
            '$BUILD_DIR/mongo/db/session/logical_session_cache_impl',
            '$BUILD_DIR/mongo/db/session/logical_session_id',
            '$BUILD_DIR/mongo/db/session/logical_session_id_helpers',
            '$BUILD_DIR/mongo/db/session/session_catalog',
            '$BUILD_DIR/mongo/db/session/session_catalog_mongod',
            '$BUILD_DIR/mongo/db/session/sessions_collection',
            '$BUILD_DIR/mongo/db/session/sessions_collection_mock',
            '$BUILD_DIR/mongo/db/stats/fill_locker_info',
            '$BUILD_DIR/mongo/db/storage/wiredtiger/storage_wiredtiger',
            '$BUILD_DIR/mongo/executor/async_timer_mock',
            '$BUILD_DIR/mongo/rpc/command_status',
            '$BUILD_DIR/mongo/rpc/rpc',
            '$BUILD_DIR/mongo/shell/kms_idl',
            '$BUILD_DIR/mongo/transport/transport_layer_mock',
            '$BUILD_DIR/mongo/util/clock_source_mock',
            '$BUILD_DIR/mongo/util/net/network',
            '$BUILD_DIR/mongo/util/net/ssl_options_server',
            'change_stream_options_manager',
            'collection_index_usage_tracker',
            'commands',
            'common',
            'dbmessage',
            'fle_crud',
            'fle_mocks',
            'global_index',
            'index_build_entry_helpers',
            'index_builds_coordinator_mongod',
            'keys_collection_client_direct',
            'keys_collection_document',
            'mirror_maestro',
            'multitenancy',
            'operation_time_tracker',
            'query_exec',
            'read_write_concern_defaults_mock',
            'record_id_helpers',
            'rw_concern_d',
            'server_base',
            'server_options_servers',
            'service_context',
            'service_context_d',
            'service_context_d_test_fixture',
            'service_context_devnull_test_fixture',
            'service_context_test_fixture',
            'service_liaison_mock',
            'shard_role',
            'signed_logical_time',
            'snapshot_window_options',
            'startup_warnings_mongod',
            'ttl_collection_cache',
            'ttl_d',
            'update_index_data',
            'vector_clock',
            'vector_clock_test_fixture',
            'write_concern_options',
        ],
    )

# These unit tests rely on the config_server_test_fixture, which
# globally alters the state of the system to be in config server
# mode. The other tests are not compatible with that setting.
envWithAsio.CppUnitTest(
    target='db_unittest_with_config_server_test_fixture_test',
    source=[
        'key_generator_update_test.cpp',
        'keys_collection_cache_test.cpp',
        'keys_collection_manager_sharding_test.cpp',
        'logical_time_validator_test.cpp',
    ],
    LIBDEPS=[
        'auth/authmocks',
        'keys_collection_client_direct',
        's/config_server_test_fixture',
        'vector_clock',
    ],
)

asioEnv.CppIntegrationTest(
    target='db_integration_test',
    source=[
        'nesting_depth_test.cpp',
        'exhaust_cursor_currentop_integration_test.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/client/clientdriver_network',
        '$BUILD_DIR/mongo/executor/network_interface_fixture',
        '$BUILD_DIR/mongo/rpc/message',
        '$BUILD_DIR/mongo/transport/transport_layer_egress_init',
        '$BUILD_DIR/mongo/util/version_impl',
    ],
)

env.CppLibfuzzerTest(
    target='op_msg_fuzzer',
    source=[
        'op_msg_fuzzer.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/base',
        'op_msg_fuzzer_fixture',
    ],
)

env.Benchmark(
    target='commands_bm',
    source=[
        'commands_bm.cpp',
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/idl/idl_parser',
    ],
)
