Skip to content

Improved Pascal language support#7220

Closed
lebao3105 wants to merge 11 commits intoxmake-io:devfrom
lebao3105:feat/fpcAdditions
Closed

Improved Pascal language support#7220
lebao3105 wants to merge 11 commits intoxmake-io:devfrom
lebao3105:feat/fpcAdditions

Conversation

@lebao3105
Copy link
Contributor

@lebao3105 lebao3105 commented Jan 13, 2026

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lebao3105, 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 significantly improves Pascal language support within Xmake by introducing a comprehensive set of new configuration options and the underlying logic to translate these options into Free Pascal Compiler (FPC) specific flags. This enhancement allows users to precisely control various aspects of Pascal compilation, such as managing search paths for units and includes, defining or undefining preprocessor macros, and specifying the desired Pascal language dialect, thereby offering greater flexibility and compatibility for Pascal projects.

Highlights

  • Expanded Pascal API: New API functions have been introduced for target, option, package, and toolchain scopes, enabling more granular control over Pascal compilation settings such as unit directories, include directories, preprocessor defines/undefines, and language modes.
  • Enhanced Configuration Flags: The set_nameflags configuration in xmake/languages/pascal/xmake.lua has been updated to recognize and apply the newly added Pascal-specific settings for both object and binary targets, ensuring these configurations are properly propagated during the build process.
  • Free Pascal Compiler (FPC) Integration: New utility functions have been added to xmake/modules/core/tools/fpc.lua to translate Xmake's Pascal configuration options into the corresponding Free Pascal Compiler (FPC) command-line flags, including -FI for include directories, -Fu for unit directories, -d for defines, -u for undefines, and -M for language modes.

🧠 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.

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
Contributor

@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 improves Pascal language support by adding several new APIs for compiler flags like include paths, unit paths, defines, and language modes. The changes are mostly correct and well-implemented.

I've left a specific comment in xmake/modules/core/tools/fpc.lua to make the language mode handling more robust.

Additionally, I noticed an inconsistency in xmake/languages/pascal/xmake.lua. The new nameflags have been added to the binary target kind, but not to the shared target kind. Since fpc handles both compilation and linking in a single step, shared targets would likely benefit from these flags as well. Please consider updating the shared section for consistency.

@waruqi
Copy link
Member

waruqi commented Jan 14, 2026

Please do not add new apis. set_languagemode, add_unitdirs

Any new API should have its design discussed in detail in issues, and a decision made on whether it is truly necessary, rather than being added arbitrarily to a PR.

In addition, the design of APIs should be as abstract as possible and be universal, rather than being provided for use by a specific language such as Pascal.

If it's only used for a specific language, I usually recommend using add_fcflags to set it directly.

@waruqi waruqi moved this to In progress in Xmake Project Jan 15, 2026
@waruqi waruqi moved this from In progress to Done in Xmake Project Jan 15, 2026
@waruqi waruqi removed this from Xmake Project Jan 15, 2026
@lebao3105
Copy link
Contributor Author

Known issue(s):

Introduced via the code below.

Flags are somehow re-added

lebao3105@ultramarine Commands-collection on  master [✘!?] via 🌙 
❯ XMAKE_PROGRAM_DIR=$(pwd)/../xmake/xmake xmake b -v selected
[ 27%]: archiving.release libcustcustc.a
/usr/bin/ar -cr build/linux/x86_64/release/libcustcustc.a build/.objs/custcustc/linux/x86_64/release/include/custcustc.c.o
[ 54%]: linking.release dir
/usr/bin/fpc -dbg:=begin -ded:=end -dretn:=procedure -dfn:=function -dlong:=longint -dulong:=longword -dint:=integer -dbool:=boolean -dreturn:=exit -Fiinclude -Fuinclude -Mfpc -O3 -Sa -Si -Sm -Sc -Sx -Co -CO -Cr -CR -gl -k-lc -k-Lbuild/linux/x86_64/release -Xs -dbg:=begin -ded:=end -dretn:=procedure -dfn:=function -dlong:=longint -dulong:=longword -dint:=integer -dbool:=boolean -dreturn:=exit -Fiinclude -Fuinclude -Mfpc -k-lcustcustc -obuild/linux/x86_64/release/dir src/dir/dir.pp
error: Free Pascal Compiler version 3.2.2 [2025/08/02] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling src/dir/dir.pp
dir.pp(48,9) Error: Identifier not found "try"
dir.pp(49,13) Fatal: Syntax error, ";" expected but "identifier ISNAMEVALID" found
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode

Notice how definitions (ones starting with -d) and more get duplicated (add_includedirs, add_unitdirs, set_languages).

Example(s)

add_rules("mode.debug", "mode.release", "mode.releasedbg")
add_rules("plugin.compile_commands.autoupdate")

target("dir")
	set_kind("binary")
	set_languages("pascal")

	add_files("src/dir/dir.pp")
	add_rules("pascal")
	add_deps("custcustc")
	add_defines(
		"bg:=begin", "ed:=end", "retn:=procedure",
		"fn:=function", "long:=longint", "ulong:=longword",
                "int:=integer", "bool:=boolean", "return:=exit"
	) -- add -d<definition> flags
	add_pcflags("-Sa", "-Si", "-Sm", "-Sc",
             "-Sx", "-Co", "-CO", "-Cr", "-CR", "-gl") -- add flags into the compiler as-is
	add_includedirs("include") -- add -Fi<includedir> flags
	add_unitdirs("include") -- add -Fu<unitdir> flags

@lebao3105
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@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 significantly expands Pascal language support in xmake by adding new APIs and wiring them up for the Free Pascal Compiler. The changes introduce support for include directories, unit directories, defines, and other compiler/linker settings.

My review has identified a few critical issues:

  • In xmake/languages/pascal/xmake.lua, the nameflags for object targets incorrectly include linker flags, while the nameflags for binary and shared targets are missing essential linker flags, which would break linking and dependency tracking.
  • In xmake/modules/core/tools/fpc.lua, the implementation for handling exceptions is logically incorrect and will produce the opposite flag for disabling exceptions.

I've provided detailed comments and suggestions to fix these issues. Once these are addressed, this will be a great improvement for Pascal developers using xmake.

@lebao3105 lebao3105 marked this pull request as ready for review January 18, 2026 11:24
@waruqi
Copy link
Member

waruqi commented Jan 18, 2026

add_unitdirs is only for pascal, However, all abstract APIs should be able to be used in multiple languages, not just Pascal.

However, all abstract APIs should be able to be used in multiple languages, not just Pascal.

unitfile appears to correspond to objectfile in other languages, but currently no other language requires support for configuring search directories for individual objectfiles.

@waruqi waruqi mentioned this pull request Jan 23, 2026
@waruqi
Copy link
Member

waruqi commented Jan 23, 2026

#7260

@lebao3105 lebao3105 closed this Jan 24, 2026
@waruqi
Copy link
Member

waruqi commented Jan 25, 2026

done #7260

, "target.add_shflags"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
, "target.add_unitdirs"
, "target.add_includedirs"
Copy link
Member

@waruqi waruqi Jan 25, 2026

Choose a reason for hiding this comment

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

it will break something, we should move to path api. #7260

@lebao3105 lebao3105 deleted the feat/fpcAdditions branch February 15, 2026 17:33
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