-
-
Notifications
You must be signed in to change notification settings - Fork 630
Description
Hi, I hope I can post this here. If this is inappropriate, please just close the issue. I was asking for help on a forum and the question (together with the linked repo) will give a lot of context, so I'll just paste it here. Obviously, I don't expect any maintainer to help me, but maybe this is use case that nobody anticipated:
Okay, where to start? Sorry to say, but I'm not a Rust guy (Go is my weapon of choice ATM) and I guess some would say, this is not Rust issue. So bear this in mind. While coding, I wanted few features (that might exist, but I don't know where), that I thought I could build. I present to you Jerry's Handy Utility: https://github.com/BlueriteSoul/jhu/ I was frustrated with not being able to easily find out, how much code does it take to have -insert_project- built. GitHub breaks down language distribution in a project, and hitting the API, you can learn how many bytes are written in which language. But no LOC report. I thought, why not just clone the repo, and count the lines. Well, that's what jhu -loc does, and on the first project it failed. You see, the project came with dependencies bundled, so it still had no idea how many LOC. Anyway, I looked it up, and found tools already built for this. I thought, for educational purposes (anyone can run a command programmatically, jhu -ol has no problems with invoking an external utility) I should statically link a foreign library. And that brings me to Rust.
I chose Tokei: https://github.com/XAMPPRocky/tokei/ and started fiddling about. With the help of AI, I managed to do something, but it wasn't obvious what actually happened. I figured it out - I interfaced with just a function, that just returned lines of code (no other figures from the tokei report were included, just the total code column). This can be observed if you set the head to commit: 0022f116a4cceff79e33bbac292f0b5fe7d51f65 (I didn't have the tokei_referece there at the time, so you won't be able to see the Rust code for this behaviour, but the behaviour is observable, as I bundled the libtokei.a file). Since this was unintended behaviour, I tried to fix it, but it turns out, it's not that simple. So I will attempt to describe the problem.
Tokei claims in its README: "Tokei is also a library allowing you to easily integrate it with other projects." Not being a Rust guy, I'm just not sure if this should help me or not. It seems to me, that the way to call foreign code is by exposing a function. But I want the whole thing to run. I tried to hack it, so main.rs really just calls the real main.rs (I had to modify Cargo.toml, obviously, but really, I only touched src/main.rs, src/cli_runner.rs, src/lib.rs) and exposing that function, but it doesn't work. Based on the symptoms, it seems that Tokei tries (and I guess succeeds) reading from the stdin, despite I am parsing the input in Go and passing that. Even if I hardcode --help as the only argument, I still get:
Running Tokei via embedded Rust library...
error: invalid value 'cf' for '--output <output>': "cf" is not a supported serialization format
For more information, try '--help'.```
No matter what I do, I can't get the intended behaviour, which is basically just "jhu -locf" becoming an alias for "tokei" and if everything goes well, I'd like to pass flags, so "jhu -locf --help" would become "tokei --help" and so on and so forth. Can anybody point me into the right direction? Is this a wrong approach? I can make it work, by just invoking the command, but I'd like to successfully embed some foreign code in my project.
Any advice will be appreciated, thank you.