Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

@rules_swift_package_manager//config_settings/spm/platform:macos matching in a linux docker container on mac os #1174

Open
roya1v opened this issue Jul 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@roya1v
Copy link
Contributor

roya1v commented Jul 16, 2024

I'm trying to build a swift project in a linux docker container on mac os and I get an error that a module cannot be imported, because it's only available on apple platforms. This import should be hidden behind a flag that should be only passed on apple platforms. But it's still getting passed on Linux.
Here is the BUILD.bazel which doesn't work

swift_library(
    name = "SystemPackage.rspm",
    always_include_developer_search_paths = True,
    copts = [
        "-DSWIFT_PACKAGE",
        "-DSYSTEM_PACKAGE",
    ] + select({
        "@rules_swift_package_manager//config_settings/spm/configuration:debug": ["-DENABLE_MOCKING"],
        "@rules_swift_package_manager//config_settings/spm/platform:ios": ["-DSYSTEM_PACKAGE_DARWIN"],
        "@rules_swift_package_manager//config_settings/spm/platform:macos": ["-DSYSTEM_PACKAGE_DARWIN"], # <- this
        "@rules_swift_package_manager//config_settings/spm/platform:tvos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "@rules_swift_package_manager//config_settings/spm/platform:visionos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "@rules_swift_package_manager//config_settings/spm/platform:watchos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }),
# ...

If I comment this line out or replace it for the platform condition behind this one, it works just fine:

swift_library(
    name = "SystemPackage.rspm",
    always_include_developer_search_paths = True,
    copts = [
        "-DSWIFT_PACKAGE",
        "-DSYSTEM_PACKAGE",
    ] + select({
        "@rules_swift_package_manager//config_settings/spm/configuration:debug": ["-DENABLE_MOCKING"],
        "@rules_swift_package_manager//config_settings/spm/platform:ios": ["-DSYSTEM_PACKAGE_DARWIN"],
        "@platforms//os:macos": ["-DSYSTEM_PACKAGE_DARWIN"], # <- like this
        "@rules_swift_package_manager//config_settings/spm/platform:tvos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "@rules_swift_package_manager//config_settings/spm/platform:visionos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "@rules_swift_package_manager//config_settings/spm/platform:watchos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }),
    deps = ["@swiftpkg_swift_system//:CSystem.rspm"],

If it helps here is the code https://github.com/roya1v/generics-pizza/blob/main/BUILD.bazel#L10 (It uses a fork of this repo for a different fix, but I also tried it with the upstream version)

@cgrindel cgrindel added the bug Something isn't working label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants