-
-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Pascal Language Support #388
Comments
As long as it is a native binary compatible compiled language with c/c++, I will consider support it in xmake, but currently xmake is mainly focused on c/c++. So I can't guarantee which version and time point to support it. |
If more than 5 people request this feature, I will consider supporting it. |
I would like to voice my request for this feature. Especially considering the simplicity and flexibility of the fpc compilation process. While freepascal is nice and simple to compile for, all of the other tasks related to but not directly part of the building of the binary. It would be nice to have the ability to conditionally select shared library file to copy into the bin folder, and other similar tasks. Anyway, I just found xmake in a recent project, and think it is really nice, and would like to be able to use it for many of my freepascal projects :) |
ok, I will consider it in version 2.5.6 |
some references: |
Maybe I need some example projects and makefiles to start working, such as hello world and static/shared program for free pascal. |
Cross-platform tutorial/tips: |
Shared libraries: library SimpleLib;
function MySucc(AVal : Int64) : Int64; stdcall;
begin
Result := System.Succ(AVal);
end;
function MyPred(AVal : Int64) : Int64; stdcall;
begin
Result := System.Pred(AVal);
end;
exports
MySucc,
MyPred;
end. Command: fpc -Sd SimpleLib.pas Source: freepascal-wiki Static libraries: Wiki.FreePascal: |
Thanks, but this can only compile a single pas file and execute the link directly. How do I just compile and generate object files, and then call the linker to link them. like this fpc -c -ofoo.o foo.pas |
done, examples: https://github.com/xmake-io/xmake/tree/dev/tests/projects/pascal add_rules("mode.debug", "mode.release")
target("test")
set_kind("binary")
add_files("src/*.pas") we need install fpc compiler. $ xmake -rv
[ 33%]: linking.release test
/usr/local/bin/fpc -O3 -Sd -Xs -k-lz -obuild/macosx/x86_64/release/test src/main.pas
[100%]: build ok!
$ xmake r
Hello, world. |
Nice. I will try to test soon. For static lib flag add:
|
Fpc library to C app (ffi) |
done |
? Does this require xmake to do something extra? |
Ok. I wiil test now. |
Because I am not familiar with pascal, there is no example of dynamic library and static library similar to hello world. |
WorksC library: #include <stdint.h>
extern int64_t fib(int64_t n)
{
return n > 1 ? fib(n - 1) + fib(n - 2) : 1;
} Pascal app: program hello;
function fib(n: Int64): Int64;
cdecl; external 'bar';
var
Value: Integer;
begin
Value := 5;
WriteLn(fib(Value));
end. XMake build: add_rules("mode.debug", "mode.release")
target("bar")
set_kind("static") -- works
-- set_kind("shared") -- works
add_files("src/bar.c")
target("hello")
set_kind("binary")
add_deps("bar")
add_files("src/hello.pas") FailPascal library [shared / static]: library libbar;
{$mode objfpc}{$H+}
function fib(n : Int64) : Int64; cdecl;
begin
if n > 1 then
begin
Result := fib(n - 1) + fib(n - 2);
end
else
Result := 1;
end;
exports
{$IFDEF DARWIN} {OS X entry points}
fib name '_fib',
{$ENDIF}
fib;
end. XMake build: add_rules("mode.debug", "mode.release")
target("bar")
set_kind("static") -- don't works
-- set_kind("shared") -- don't works
add_files("src/bar.pas")
target("hello")
set_kind("binary")
add_deps("bar")
add_files("src/hello.pas") hello-app w/ static-lib output: # build
[ 33%]: linking.release libbar.a
/usr/bin/fpc -O3 -Xt -obuild/linux/x86_64/release/libbar.a src/bar.pas
[ 66%]: linking.release hello
/usr/bin/fpc -O3 -Sd -k-Lbuild/linux/x86_64/release -Xs -k-lbar -obuild/linux/x86_64/release/hello src/hello.pas
[100%]: build ok!
# run
/build/linux/x86_64/release/hello: error while loading shared libraries: libbar.a: cannot open shared object file: No such file or directory hello-app w/ shared-lib output: # build
[ 33%]: linking.release libbar.so
/usr/bin/fpc -O3 -Sd -Xs -obuild/linux/x86_64/release/libbar.so src/bar.pas
[ 66%]: linking.release hello
checking for flags (-k-rpath=@loader_path) ... ok
/usr/bin/fpc -O3 -Sd -k-Lbuild/linux/x86_64/release -k-rpath=$ORIGIN -Xs -k-lbar -obuild/linux/x86_64/release/hello src/hello.pas
[100%]: build ok!
➜ hello ./build/linux/x86_64/release/hello
# run
./build/linux/x86_64/release/hello: symbol lookup error: ./build/linux/x86_64/release/hello: undefined symbol: calloc, version GLIBC_2.2.5
`` |
New test - WorksPascal - Shared lib Pascal app: program Hello;
uses sysutils, dynlibs;
procedure UseLib;
type
TMyFunc=function (n:Integer):Integer; stdcall;
var
MyLib: TLibHandle = dynlibs.NilHandle;
MyFunc: TMyFunc;
FuncResult: integer;
begin
MyLib := LoadLibrary('libbar.' + SharedSuffix);
if MyLib = dynlibs.NilHandle then Exit; //Lib was not loaded successfully
MyFunc:= TMyFunc(GetProcedureAddress(MyLib, 'fib'));
FuncResult:= MyFunc (5); //Executes the function
if MyLib <> DynLibs.NilHandle then if FreeLibrary(MyLib) then MyLib:= DynLibs.NilHandle; //Unload the lib, if already loaded
writeln('Result fibonacci (Lib): '+InttoStr(FuncResult));
end;
procedure Main;
begin
UseLib;
end;
begin
Main;
end. Pascal lib: library bar;
{$mode delphi} // delphi mode: fpc -Sd
// {$mode objfpc}{$H+} // fp mode: fpc -S2
function fib(n : Int64) : Int64; stdcall;
begin
if n > 1 then
begin
Result := fib(n - 1) + fib(n - 2);
end
else
Result := 1;
end;
exports
{$IFDEF DARWIN} {OS X entry points}
fib name '_fib',
{$ENDIF}
fib;
end. XMake build add_rules("mode.debug", "mode.release")
target("bar")
-- set_kind("static") -- don't works
set_kind("shared") -- works
add_files("src/bar.pas")
target("hello")
set_kind("binary")
add_deps("bar")
add_files("src/hello.pas") |
-Xt (-static lib) cannot generate static library. libbar.a is still dynamic library.
|
I fixed it, and added shared project tempalte. |
Thank you, I will also run some tests with my projects, this weekend. I will try to convert a couple of them to utilize xmake, instead of FPCs built in build system. I have been away for about 3 weeks, recovering from a nasty virus. Otherwise I would have jumped on this issue :) |
I would like you to add more extensions referring to pascal like:
Unit files: Add flag e.g.: Delphi mode: |
done
you can use |
I removed the static library example, because I tried some methods and it does not support generating static library well. In addition, I saw that the official fpc did not provide support for it. https://gitlab.com/freepascal.org/fpc/documentation/-/issues/22272 |
Wow! I understand. I think it's unfortunate that you don't have static-lib support. Thanks again @waruqi! Good work, XMake +1 support. |
I want to leave a comment here, expressing my gratitude. I can now use xmake for over 75% of my projects, and it is so much better than make and cmake. Thank you bunches 😃 |
It would be interesting to add in this project support for the pascal language adhering to compatibility with FreePascal and/or Delphi.
The text was updated successfully, but these errors were encountered: