Skip to content

time: Prevent linux time functions from being included in non-linux platforms#26596

Merged
spytheman merged 3 commits intovlang:masterfrom
programmingkidx:linux-time-func-fix
Feb 14, 2026
Merged

time: Prevent linux time functions from being included in non-linux platforms#26596
spytheman merged 3 commits intovlang:masterfrom
programmingkidx:linux-time-func-fix

Conversation

@programmingkidx
Copy link
Copy Markdown
Contributor

Currently the time modules methods now() and utc() always include linux_now() or linux_utc() in the function call. This is extra code that does nothing to help and does prevent compiling V on Mac OS 10.4. This patch makes sure only the code for the specified operating system is used. It also provides a catch-all case if the host operating system is not already specifically handled.

@spytheman
Copy link
Copy Markdown
Contributor

This is extra code that does nothing to help and does prevent compiling V on Mac OS 10.4.

What exact error do you get on Mac OS 10.4 (which was last released in 2007 afaik)?

Used "v fmt -w" on the file to format it.
@programmingkidx
Copy link
Copy Markdown
Contributor Author

programmingkidx commented Feb 13, 2026

Unfortunately I didn't record the exact error message I received. It was probably an undefined function because linux_now() uses clock_gettime(). clock_gettime() is not available in Mac OS 10.4.

@programmingkidx
Copy link
Copy Markdown
Contributor Author

I was thinking about simplifying both now() and utc() to just use the generic C implementations in their "$else" clause. Is there a good reason not to do this?

@spytheman
Copy link
Copy Markdown
Contributor

I was thinking about simplifying both now() and utc() to just use the generic C implementations in their "$else" clause. Is there a good reason not to do this?

I do not see one; you can extract a function from the common block and call it in both cases.

@spytheman
Copy link
Copy Markdown
Contributor

Make sure to take care of the failing CI for FreeBSD and OpenBSD however, for example https://github.com/vlang/v/actions/runs/21969029262/job/63474997526?pr=26596 .

@programmingkidx
Copy link
Copy Markdown
Contributor Author

Trying to pass all tests is going to be very hard. I just removed my patch from my repo. Then I did a 'git pull'. Now I am at commit edd4a71. I then ran 'make'. It completed without any problems. I then ran 'v test .' in the vlib/time module and saw this score:
Summary for all V _test.v files: 14 failed, 1 passed, 15 total. Elapsed time: 1120 ms, on 7 parallel jobs. Comptime: 4698 ms. Runtime: 91 ms.

How am I suppose to pass all tests when there are so many issues with the time module?

Simply the changes.
@spytheman
Copy link
Copy Markdown
Contributor

spytheman commented Feb 14, 2026

How am I suppose to pass all tests when there are so many issues with the time module?

The tests (for the time module in vlib) are supposed to be run with ./v test vlib/time (from the top level folder of the project), and the CI does so. The reason for that is fixed in #26600 , but that will not be merged for now (until its own CI passes completely).

As for testing on FreeBSD or OpenBSD, that can be done in a VM (see .github/workflows/freebsd_ci.yml for the setup that the CI uses).

If you do not want to do that locally for whatever reason, you can also push changes in your private fork, without making a PR, then read the logs of the failed jobs (the failures are usually listed near the bottom, and the web ui scrolls automatically to the end, so they are easier to find/analyze) until the corresponding CI jobs pass on your private fork, and then make a PR.

Copy link
Copy Markdown
Contributor

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to merge the PR as it is, since after your latest change, everything passed, and it will minimize the delta for your future PR.

@programmingkidx
Copy link
Copy Markdown
Contributor Author

programmingkidx commented Feb 14, 2026

Thank you for letting me know. I just ran "./v test vlib/time" and all the tests passed 😁

---- Testing... -----------------------------------------------------------------------------
                 retrying 1/1 of vlib/time/operator_test.v ; known flaky: false ...
                 retrying 1/1 of vlib/time/Y2K38_test.v ; known flaky: false ...
 OK    [ 1/15] C:   507.9 ms, R:   110.463 ms vlib/time/misc/misc_test.v
 OK    [ 2/15] C:   542.6 ms, R:   145.087 ms vlib/time/chrono_test.v
 OK    [ 3/15] C:   578.2 ms, R:   173.198 ms vlib/time/duration_test.v
 OK    [ 4/15] C:   600.4 ms, R:   355.423 ms vlib/time/Y2K38_test.v
                 retrying 1/1 of vlib/time/parse_test.v ; known flaky: false ...
 OK    [ 5/15] C:   600.5 ms, R:   355.450 ms vlib/time/operator_test.v
 OK    [ 6/15] C:   600.7 ms, R:   355.548 ms vlib/time/custom_format_test.v
 OK    [ 7/15] C:   600.4 ms, R:    73.958 ms vlib/time/parse_test.v
 OK    [ 8/15] C:   380.7 ms, R:    94.384 ms vlib/time/relative_test.v
 OK    [ 9/15] C:   350.0 ms, R:   158.869 ms vlib/time/stopwatch_test.v
 OK    [10/15] C:   410.8 ms, R:    73.348 ms vlib/time/time_addition_test.v
 OK    [11/15] C:   437.9 ms, R:    79.426 ms vlib/time/time_test.c.v
 OK    [12/15] C:   472.8 ms, R:    99.356 ms vlib/time/time_format_test.v
 OK    [13/15] C:   410.1 ms, R:   154.010 ms vlib/time/unix_test.v
 OK    [14/15] C:   422.2 ms, R:   165.902 ms vlib/time/utc_vs_local_time_test.v
 OK    [15/15] C:   607.2 ms, R:   288.234 ms vlib/time/time_test.v
---------------------------------------------------------------------------------------------
Summary for all V _test.v files: 15 passed, 15 total. Elapsed time: 1855 ms, on 7 parallel jobs. Comptime: 7522 ms. Runtime: 3038 ms.

@spytheman spytheman merged commit 02a6293 into vlang:master Feb 14, 2026
78 checks passed
cestef pushed a commit to cestef/v that referenced this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants