Skip to content
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

Support for cppfront #4132

Closed
paul-reilly opened this issue Aug 28, 2023 · 8 comments
Closed

Support for cppfront #4132

paul-reilly opened this issue Aug 28, 2023 · 8 comments

Comments

@paul-reilly
Copy link
Contributor

Xmake Version

v2.8.1+dev.bdb28e5

Operating System Version and Architecture

Linux 6.1.44-1-MANJARO x86_64 GNU/Linux

Describe Bug

When running this xmake.lua file to generate a single .cpp file, the build fails on first run even though the .cpp file is generated.

rule("cppfront")
    set_extensions(".cpp2")
    on_load(function(target)
        local rule = target:rule("c++.build"):clone()
        rule:add("deps", "cppfront", { order = true })
        target:rule_add(rule)
    end)

    on_build_file(function(target, sourcefile, opt)
        cprint('${cyan}cppfront compiling: ${bright green}%s', sourcefile)
        local dir = path.directory(sourcefile)
        local outdata, errdata = os.iorunv("cppfront", { sourcefile })
        cprint("res: '%s'  :  '%s'", outdata, errdata)
    end)


target("app")
    set_kind("binary")
    add_rules("cppfront")
    add_files("src/*.cpp2")
    add_files("src/*.cpp")
    add_packages("fmt")

Expected Behavior

The generated main.cpp is compiled.

Project Configuration

Test cpp2 file:

main: () -> int = 
    println("Hello world!\n");

println: (msg: _) -> int = {
    std::cout << "msg: " << msg;
    return 0;
}

Additional Information and Error Logs

Message with failed compilation:

>xmake -rv                                  ✔ 
cppfront compiling: src/main.cpp2
res: 'src/main.cpp2... ok (all Cpp2, passes safety checks)

'  :  ''
[ 50%]: linking.release app
/usr/bin/g++ -o build/linux/x86_64/release/app -m64 -L/home/dev/.xmake/packages/f/fmt/10.0.0/cf4a2efd8ed34f738dfde8eaa4fb9660/lib -lfmt
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
error: execv(/usr/bin/g++ -o build/linux/x86_64/release/app -m64 -L/home/dev/.xmake/packages/f/fmt/10.0.0/cf4a2efd8ed34f738dfde8eaa4fb9660/lib -lfmt) failed(1)
warning: ./xmake.lua:26: cannot match add_files("src/*.cpp") in target(app)
@waruqi
Copy link
Member

waruqi commented Aug 29, 2023

I will attempt to add a builtin cppfront rule.

@waruqi waruqi changed the title C++ file generated in custom rule: not compiled on first run Support for cppfront Aug 29, 2023
@waruqi waruqi added this to the v2.8.3 milestone Aug 29, 2023
@paul-reilly
Copy link
Contributor Author

Official cppfront support would be a good addition to xmake.

However this issue is general to files generated at build time for compilation with that pattern, which is used in the xmake documentation. I have seen it when adding a rule for files generated by drogon_ctl, for example.

@waruqi
Copy link
Member

waruqi commented Aug 29, 2023

@paul-reilly
Copy link
Contributor Author

Thanks, the docs imply that the rule in the first post here would work:

https://xmake.io/#/manual/custom_rule?id=ruleadd_deps

I don't think a description of the autogen_codedep pattern is in the docs yet.

@waruqi
Copy link
Member

waruqi commented Aug 29, 2023

https://xmake.io/#/manual/custom_rule?id=ruleadd_deps

This is just to say the dynamic creation and injection of rules, not the automatic generation of code.

It's just that I happened to put in a small example of dynamic injection about cppfront.

@waruqi
Copy link
Member

waruqi commented Aug 29, 2023

I added it. cppfront #4140

@waruqi waruqi closed this as completed Aug 29, 2023
@paul-reilly
Copy link
Contributor Author

Good stuff!

Imo that cppfront example should be removed from the docs because it implies that enforcing rule-ordering means that generated files are then compiled.

@cassepipe
Copy link

Thanks waruqi !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants