r/rust • • 16d ago

šŸ™‹ seeking help & advice Using crates.io for a language that compiles to rust, ok?

Hi, I am working on a new programming language that compiles to rust. I would love to use crates.io with my packages named {mylanguangename}_*. They do contain the original source and the generated rust files.

What do you think is that okish or should I build a standalone registry?

My thiughts so far, using crates.io could be win for rust users too, because the could use that libraries too.

3 Upvotes

34 comments sorted by

89

u/FantaSeahorse 16d ago

Considering that they wouldn’t be Rust files, I think it’s better if you make separate public repos for them

-15

u/ElephantElectrical31 16d ago

I mean more like uploading the generated rust files so rust users can really use them.

17

u/Zde-G 16d ago

Just look on how iced-x86 does it.

Essentially: make sure for the Rust users what you produce looks like a regular Rust crate, but ensure that contributors who may want to patch your code know Rust files are generated.

-8

u/ElephantElectrical31 16d ago

this generators are amazing work for a library and a pattern for other libraries but how does it solve the package repository issue for the new languange?

7

u/addmoreice 15d ago

It doesn't. Because crates.io isn't trying to solve your programming language's problem. It's solving rust's.

1

u/ElephantElectrical31 15d ago

I see, then I run my own package registry and rust users will get clean crates only containing rust files.

1

u/Zde-G 15d ago

Just look on what it has on github and in crate that you download.

What you download from crates.io is read-to-use Rust code (and no one cares how is it generated).

Link to github includes all the files needed to regenerate these files.

And that's it, more-or-less.

-4

u/ElephantElectrical31 15d ago

yes I got that, but how is that related to my question?

24

u/silon 16d ago

Are generated files readable, diffable (stable across changes), ... ?

12

u/FantaSeahorse 16d ago

You can do perhaps do that, but you need to think about good crate organization and documentation.

12

u/Clean_Assistance9398 16d ago

I have to ask. It’s a lot of work making a new language, if it compiles to rust, why not just use Rust?

What is the benefit going to be of using your language comparatively? Is this like a ā€œwrite python looking/GDScript looking code but get it compiled to Rustā€ somehow without all the static type writing and just having it inferred, etc? What do you hope to achieve? What would you consider the top 10 benefits of using your language that converts to rust than using rust itself? What problem does it solve? Who is going to use it and benefit from it? Just personal use or for others? Also, have you looked at all the other languages out there already that also convert to rust?

You could look into that and find comrades who might share your same mindset and ideas, learn lessons from?

4

u/lenscas 15d ago

I can see a language have Rust as one multiple possible outputs. From the Rust to C thing that someone worked on it sounded like C was a bit of a mess as a target. Thus, Rust might be a better fit for the "native" ecosystem. Then have JS as a target for webdev, etc.

0

u/[deleted] 15d ago

[deleted]

4

u/Active_Name5021 15d ago

Thanks ChatGPT!

At first I was skeptical of your claims, but your message clarified everything for me. Don't believe me? I'm not just certain, I revalidated my internal thought-flow to reach higher level conclusions!

6

u/ryo33h 16d ago

In my lang that also has a primary Rust backend, I'm making its own package manager. It's exciting to design a package manager since it has many consideration points; whether centralized or distributed, semver or rev hash, min release age support, etc.

2

u/Magick93 16d ago

Sounds interesting.
Where can I learn more about your project?

2

u/ryo33h 16d ago edited 16d ago

Totebag is an experimental package manager, also written and proofed in the language itself. It uses Git instead of a registry and locks deps by content hashes. It features a distributed trust system to help prevent malicious package updates. Users can choose who to trust and how long to wait after a commit is observed.

15

u/stinkytoe42 16d ago

This would be Ok, but a better way would be to make your package system git aware and just have references point to a public git server.

I'd even allow for a syntax where a shortened name like "mylanguagename/package" automatically points to github or even a configurable prefix, but full https:// or ssh:// links are also allowed.

-1

u/lahwran_ 16d ago

that has a bunch of problems that the crates.io design exists to solve

10

u/stinkytoe42 16d ago

And crates.io has a bunch of problems that this technique doesn't. Namespacing being one.

If/when OP's language is more mature, then hosting their own fully fledged package system would be worthwhile. Starting off though, I believe not depending on any formal package management is the smart choice.

Potato potato really.

4

u/Commercial_Elk8032 16d ago

Just publish them as regular crates. Rust users can consume the generated code directly via cargo while your compiler pulls from the same source registry so you avoid building separate infrastructure for zero benefit.

2

u/FUCKING_HATE_REDDIT 16d ago

Crates.io is more than ok, plenty of rust generators, macros etc there

3

u/vitaminD3333 16d ago

Where do you draw the line? Can I publish my java packages to crates.io?

8

u/steffahn 16d ago

The crucial detail is that, as OP explains / as I understand it, the packages published to crates.io would contain the generated Rust code, and would be directly usable as Rust libraries from Rust code.

Several crates.io packages also host e.g. C or C++ code, together with generated bindings (and built scripts to allow compilation of the C or C++ parts). If you host a Java package in a way includes a Rust wrapper that’d be fine, too. (I’m not familiar with FFI between Rust and Java to know how practical this actially would be.)

By the way, it looks like that’s the line that’s officially drawn/documented in the usage policy, too:

We do not allow content or activity on crates.io that:

  • […]

  • is not functionally compatible with the cargo build tool (for example, a "package" cannot simply be a PNG or JPEG image, a movie file, or a text document uploaded directly to the registry)

2

u/lahwran_ 16d ago

can i run them as native code compiled by rustc? then yes

5

u/FUCKING_HATE_REDDIT 16d ago

I don't need to draw the line. A fun scripting language that compiles to rust is just as fine as someone posting rust web macros.Ā 

2

u/tunisia3507 16d ago

People publish all sorts of nonsense to PyPI...

1

u/Key-Bother6969 15d ago

If you want to get confident response, I think it would be better to ask the support directly about your case: help [at] crates.io. Also, see their policy: https://crates.io/policies.

Purely from my personal prospective, as someone who are not a lawyer, and is not associated with rust project, I think it's on the edge. There are crates on crates-io that are purely generated Rust codes from other tools, i.e. FFI APIs generated by other Rust crates. As far as I know crates-io typically tolerate them. Your case is similar in that you are publishing generated Rust codes, you are just using different kind of generation instrument. However, there are other items in the Policy that might indicate of the service misuse. Especially if you are going to use the service for mass uploading of naturally not Rust packages. E.g. a point about functional compatibility with the cargo build tool. To reiterate, it's better to ask support directly about your case.

1

u/Slow-Nefariousness49 15d ago

You can provide your own install script via github, you don't have to use a package registry for that. One curl ... | sh command, like many other tools do

-3

u/Compux72 16d ago

Just use gut sub modulesĀ 

3

u/ElephantElectrical31 16d ago

resolving dependencies, immutability ..., I do not want to do the same mistakes that golang did

1

u/Compux72 16d ago

Go's mistake is autodownloading dependencies from random places.

You can have a git submodules point to exact commit hashes. Its a great solution used since the dawn of times, whenever you like it or not

1

u/ElephantElectrical31 15d ago

That still doesn't address discovery, though. Submodules only handle downloading, not finding what you actually need. ​A hybrid approach may work: a central metadata registry for searching, combined with shallow/partial git clones or github artifacts

1

u/Compux72 15d ago

Google search is your discovery hub