Skip to content

Add bsd environment specific file support #26755

@kimshrier

Description

@kimshrier

Describe the feature

We have a _nix.c.v environment specific file name for any os that is not Windows. This seems overly general to me, but that is not something I want to address just yet.

I would like to add a _bsd.c.v name which would be compiled if one was on macos, freebsd, openbsd, netbsd, or dragonfly.

I would also like to propose an order of selection such that the most specific environment specific file is chosen. For example, assume that I am on freebsd and I have the following files in my project:

my_v_project/
    main.v
    something_default.c.v
    something_windows.c.v

I would expect main.v and something_default.c.v would be compiled since freebsd is not windows.

If I added something_nix.c.v to this directory, I would expect main.v and something_nix.c.v to be compiled since freebsd is a kind of unix.

If I then added something_bsd.c.v to this directory, I would expect main.v and something_bsd.c.v to be compiled. Since _bsd.c.v is more specific than _nix.c.v it gets chosen instead of _nix.c.v or _default.c.v.

If I added something_freebsd.c.v so that my directory now looks like this:

my_v_project/
    main.v
    something_bsd.c.v
    something_default.c.v
    something_freebsd.c.v
    something_nix.c.v
    something_windows.c.v

I would expect main.v and something_freebsd.c.v to be compiled since I have an environment specific file name that exactly matches the os.

Use Case

In vlib/fasthttp there are the following environment specific files:

fasthttp_darwin.v
fasthttp_linux.v
fasthttp_windows.v

I have copied fasthttp_darwin.v to fasthttp_freebsd.v and it works with no changes. I suspect that the same would be true for openbsd, netbsd, and dragonfly. Although I don't have openbsd, netbsd, and dragonfly systems I can test on locally.

The brute-force solution would be to create fasthttp_openbsd.v, fasthttp_netbsd.v and fasthttp_dragonfly.v files but having 5 identical copies of a file is a maintenance problem (and it smells bad).

Having a generic bsd os environment specific file would mean that we could just rename fasthttp_darwin.v to fasthttp_bsd.v and the single file would work on all 5 variants of bsd.

Proposed Solution

I propose adding a bsd os value and adopting the order of selection as described above.

I may need some assistance if I implement this.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V 0.5.1 d261348

Environment details (OS name and version, etc.)

$ v doctor
|V full version      |V 0.5.1 d261348cb906ecb34daa7d87d3a967416e2db192
|:-------------------|:-------------------
|OS                  |freebsd, 15.0-RELEASE-p3, FreeBSD 15.0-RELEASE-p3 releng/15.0-n281008-5cf7232732d5 GENERIC
|Processor           |2 cpus, 64bit, little endian
|Memory              |0.66GB/3.97GB
|                    |
|V executable        |/home/kim/Projects/v/from_github/v/v
|V last modified time|2026-03-21 19:31:37
|                    |
|V home dir          |OK, value: /home/kim/Projects/v/from_github/v
|VMODULES            |OK, value: /home/kim/.vmodules
|VTMP                |OK, value: /tmp/v_1002
|Current working dir |OK, value: /home/kim/Projects/v/from_github/v
|                    |
|env VFLAGS          |"-cc clang"
|Git version         |git version 2.53.0
|V git status        |0.5.1-193-gd261348c
|.git/config present |true
|                    |
|cc version          |FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
|gcc version         |N/A
|clang version       |FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
|tcc version         |tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 FreeBSD)
|tcc git status      |thirdparty-freebsd-amd64 204a2d97
|emcc version        |N/A
|glibc version       |N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions