8000 Fix mirb build under Cosmopolitan by katafrakt · Pull Request #6694 · mruby/mruby · GitHub
[go: up one dir, main page]

Skip to content

Fix mirb build under Cosmopolitan#6694

Merged
matz merged 2 commits intomruby:masterfrom
katafrakt:mirb-cosmopolitan
Jan 8, 2026
Merged

Fix mirb build under Cosmopolitan#6694
matz merged 2 commits intomruby:masterfrom
katafrakt:mirb-cosmopolitan

Conversation

@katafrakt
Copy link
Contributor

When I try to build mruby using Cosmopolitan (COSMO_ROOT=/path/to/cosmo ruby ./minirake MRUBY_CONFIG=cosmopolitan), I'm getting the following error:

CC    mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c -> build/host/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.o
/home/katafrakt/dev/github/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c: In function 'mirb_term_read_key':
/home/katafrakt/dev/github/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c:137:5: error: unknown type name 'fd_set'
  137 |     fd_set fds;
      |     ^~~~~~
/home/katafrakt/dev/github/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c:138:20: error: storage size of 'tv' isn't known
  138 |     struct timeval tv;
      |                    ^~
/home/katafrakt/dev/github/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c:141:5: error: implicit declaration of function 'FD_ZERO'; did you mean 'FP_ZERO'? [-Wimplicit-function-declaration]
  141 |     FD_ZERO(&fds);
      |     ^~~~~~~
      |     FP_ZERO
/home/katafrakt/dev/github/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c:142:5: error: implicit declaration of function 'FD_SET' [-Wimplicit-function-declaration]
  142 |     FD_SET(STDIN_FILENO, &fds);
      |     ^~~~~~
/home/katafrakt/dev/github/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c:146:9: error: implicit declaration of function 'select' [-Wimplicit-function-declaration]
  146 |     if (select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv) <= 0) {
      |         ^~~~~~
rake aborted! 

This seems to be related to the fact that Cosmopolitan is much mor strict when it comes to adding includes and you need to specifically include sys/select.h to access its functions.

I also added a Cosmopolitan build to the CI to avoid regressions in the future.

Compilation of mirb with Cosmopolitan fails because of missing include
(Cosmopolitan seems to be more strict than "traditional" compilers.
@gemini-code-assist
Copy link

Summary of Changes

Hello @katafrakt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical build failure that occurred when compiling the mruby project, specifically the mirb tool, using the Cosmopolitan build environment. The error was traced to missing declarations for fd_set, timeval, FD_ZERO, FD_SET, and select, which are now resolved by explicitly including sys/select.h. To safeguard against similar issues in the future, a dedicated Cosmopolitan build step has been integrated into the continuous integration pipeline.

Highlights

  • Build Fix: Resolved a build error for mirb under Cosmopolitan by adding the necessary #include <sys/select.h> to mirb_term.c.
  • CI Integration: Introduced a new CI job specifically for Cosmopolitan builds to prevent future regressions and ensure continuous compatibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/build.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly identifies and fixes a build issue on the Cosmopolitan toolchain by explicitly including <sys/select.h>. This is a good practice for portability, as it avoids relying on transitive includes. The change is correct and directly addresses the compilation errors. I've added one minor suggestion to improve code style by sorting the include directives.

Comment on lines 13 to 17
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <errno.h>

Choose a reason for hiding this comment

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

medium

While the added include is correct, for better long-term maintainability it's a good practice to keep header includes sorted alphabetically. This makes it easier to locate headers and helps prevent accidental duplicates. I'd suggest reordering this block of includes.

Suggested change
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <errno.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <termios.h>
#include <unistd.h>

@matz matz merged commit ad53019 into mruby:master Jan 8, 2026
18 checks passed
@katafrakt katafrakt deleted the mirb-cosmopolitan branch January 8, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0