Skip to content

Conversation

@joaobispo
Copy link
Member

@joaobispo joaobispo commented Nov 15, 2025

Adds exclusing builtin includes for Linux, makes the default behaviour to use these builtin includes exclusively.

The idea is to make Clava more resilent to running out-of-the-box in Linux, without problems regarding no compiler being installed, or an incompatible version being installed and picking up those includes. This is one of the most common problems when trying to run Clava.

It is still possible to specify if we want to use includes already present in the system, this is to support a more robust default behaviour.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Linux-specific builtin includes support to the ClangAstParser, making Linux use self-contained include packages similar to Windows. The changes enable Linux to use builtin libc/libcxx includes by default.

Key Changes

  • Added a new LIBC_CXX_LINUX resource for Linux-specific builtin includes
  • Updated default LibcMode behavior to use BUILTIN_AND_LIBC for both Windows and Linux platforms
  • Fixed a bug where Windows builtin resources incorrectly referenced the LLVM builtin resource version

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
ClangAstParser/src/pt/up/fe/specs/clang/ClangAstFileResource.java Adds LIBC_CXX_LINUX enum entry for the new Linux resource
ClangAstParser/src/pt/up/fe/specs/clang/ClangAstWebResource.java Defines web resource provider for libc_cxx_linux.zip
ClangAstParser/src/pt/up/fe/specs/clang/ClangAstKeys.java Updates LIBC_CXX_MODE default to include Linux alongside Windows
ClangAstParser/src/pt/up/fe/specs/clang/ClangResources.java Implements platform-specific logic for Linux builtin includes and fixes Windows version reference bug
ClangAstParser/test/eu/antarex/clang/parser/CTester.java Changes C standard from c99 to gnu99 for all C tests
ClangAstParser/test/eu/antarex/clang/parser/tests/CTest.java Adds platform-specific test for Linux timer functionality
ClangAstParser/resources/c/timer_linux.c New test file demonstrating Linux-specific time functions
ClangAstParser/resources/c/timer_linux.c.txt Expected output for the Linux timer test

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


public CTester(List<String> files) {
super("c", files, Arrays.asList("-std=c99"));
super("c", files, Arrays.asList("-std=gnu99"));
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Changing from -std=c99 to -std=gnu99 affects all C tests, not just the new Linux timer test. If this change is only needed for POSIX functions like clock_gettime() in timer_linux.c, consider using -std=c99 -D_POSIX_C_SOURCE=200112L instead to enable POSIX features without enabling all GNU extensions. Alternatively, add the flag specifically to the Linux test case if other tests don't require GNU extensions.

Suggested change
super("c", files, Arrays.asList("-std=gnu99"));
super("c", files, Arrays.asList("-std=c99"));

Copilot uses AI. Check for mistakes.
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/resource.h>
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

The include <sys/resource.h> appears to be unused. None of the functions or types from this header (e.g., getrusage, struct rusage) are used in this code. The time-related functionality comes from <time.h> and <unistd.h>.

Suggested change
#include <sys/resource.h>

Copilot uses AI. Check for mistakes.
Comment on lines 24 to 26
clock_gettime(0, &start);
sleep(1);
clock_gettime(0, &finish);
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

The calls to clock_gettime use 0 instead of CLOCK_REALTIME. While 0 happens to equal CLOCK_REALTIME on many systems, using the named constant CLOCK_REALTIME is more readable and portable. This should be changed to match the .c file which correctly uses CLOCK_REALTIME.

Suggested change
clock_gettime(0, &start);
sleep(1);
clock_gettime(0, &finish);
clock_gettime(CLOCK_REALTIME, &start);
sleep(1);
clock_gettime(CLOCK_REALTIME, &finish);

Copilot uses AI. Check for mistakes.
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/resource.h>
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

The include <sys/resource.h> appears to be unused. None of the functions or types from this header (e.g., getrusage, struct rusage) are used in this code. The time-related functionality comes from <time.h> and <unistd.h>.

Suggested change
#include <sys/resource.h>

Copilot uses AI. Check for mistakes.
@lm-sousa
Copy link
Member

I have misgivings about copy-pasted code from StackOverflow and its effects on the project's license.

Also, what is the rationale being these changes?
It should at least be documented.

@joaobispo
Copy link
Member Author

I have misgivings about copy-pasted code from StackOverflow and its effects on the project's license.

It is a test example to be used as input code, we can replace it another code (e.g., AI-generated?) that uses the time.h include.

Also, what is the rationale being these changes? It should at least be documented.

The idea is to make Clava more resilent to running out-of-the-box in Linux, without problems regarding to no compiler being installed, or an incompatible version being installed and picking up those includes (e.g., @tiagolascasas could not run Clava out-of-the-box in his laptop). I'll change the description to reflect this.

@lm-sousa
Copy link
Member

A different test file would be preferable. We can then squash the commits of this PR.
Note also Copilot's first comment.

@joaobispo
Copy link
Member Author

It is ready for another round of reviews

@lm-sousa lm-sousa merged commit 605704f into staging Nov 19, 2025
15 checks passed
@lm-sousa lm-sousa deleted the feature/builtin_includes_linux branch November 19, 2025 17:07
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.

3 participants