Don't install a module if the operating system is Windows
Asked Answered
I

2

5

Is it possible to write a META6.json file that

prints a message that the operating system is not supported

and does not try to install the module

if the operating system is Windows?

Itinerary answered 29/5, 2024 at 14:58 Comment(0)
E
5

You can craft a Build.rakumod that dies given the appropriate condition. For an example of one that fails unconditionally, see:

https://github.com/Raku/doc/blob/main/Build.rakumod

Executive answered 30/5, 2024 at 0:19 Comment(2)
class Build { BEGIN if $*DISTRO.is-win { die $*DISTRO } } This fails to build with "No such method 'build' for invocant of type 'Build'" when $*DISTRO.is-win is not true.Itinerary
@Itinerary because class Build { } has to have a build method defined. Your die logic should go inside that method. See github.com/ugexe/zef/blob/…Curlicue
C
4

Ideally this check would happen at the time of dependency resolution so that the package manager does not need to download a bunch of code and to run an e.g. Build.rakumod file before being shown that it will never work. This can sort-of be done by declaring an OS specific dependency that does not exist (and with a name that implies the parent distribution can't be installed on Windows). For example you might have a depends section that looks like the following:

    "depends"       : [
        "NativeCall",
        {
            "name": {
                "by-distro.name": {
                    "win32" : "Not-Installable-On-Windows",
                    "": ""
                }
            }
        }
    ],

On windows that would show:

===> Dependencies: NativeCall, Not-Installable-On-Windows
===> Searching for missing dependencies: Not-Installable-On-Windows
===> Failed to find dependencies: Not-Installable-On-Windows
Failed to resolve some missing dependencies (use e.g. --exclude="Not-Installable-On-Windows" to skip)

On a non-windows system it would show:

===> Dependencies: NativeCall
...

This solution is not as great as it could be though. Someone might create a distribution called Not-Installable-On-Windows in the future, and then the dependency resolution would no longer fail. Further, even when using a descriptive name as I've shown it might not be obvious to the user that the distribution depending on it isn't installable on Windows.

With that being said, the Build.rakumod solution mentioned in another answer is also viable. Going that route could be improved by creating a Distribution::Builder distribution that implements 'fail on certain OS' functionality (which would be used instead of a Build.rakumod file but work similarly) and depend on and use that in your META6.json. Using a Distribution::Builder class instead of a Build.rakumod file is generally preferred due to be declared in the META6.json file (and thus we don't need to extract an e.g. tar archive to know if we have a build step to run). See Distribution::Builder::Cmake for an example of how to create and use a Distribution::Builder class.

Curlicue answered 30/5, 2024 at 16:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.