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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone binary #1931

Merged
merged 32 commits into from
Apr 4, 2024
Merged

Standalone binary #1931

merged 32 commits into from
Apr 4, 2024

Conversation

mo8it
Copy link
Contributor

@mo8it mo8it commented Mar 28, 2024

Here is a proof of concept for #1919 of how the file embedding would be done with some macro magic 馃獎

You can take a look at the macro expansion generated by cargo-expand:

Macro expansion
static EMBEDDED_FILES: EmbeddedFiles = EmbeddedFiles {
    info_toml_content: "...",
    exercises_dir: ExercisesDir {
        readme: EmbeddedFile {
            path: "exercises/README.md",
            content: b"...",
        },
        files: &[
            EmbeddedFile {
                path: "exercises/quiz1.rs",
                content: b"...",
            },
            EmbeddedFile {
                path: "exercises/quiz2.rs",
                content: b"...",
            },
            EmbeddedFile {
                path: "exercises/quiz3.rs",
                content: b"...",
            },
        ],
        dirs: &[
            EmbeddedFlatDir {
                path: "exercises/00_intro",
                readme: EmbeddedFile {
                    path: "exercises/00_intro/README.md",
                    content: b"...",
                },
                content: &[
                    EmbeddedFile {
                        path: "exercises/00_intro/intro1.rs",
                        content: b"...",
                    },
                    EmbeddedFile {
                        path: "exercises/00_intro/intro2.rs",
                        content: b"...",
                    },
                ],
            },
            ...
        ],
    },
};

Now that we have this static instance of the type EmbeddedFiles, we can implement further logic on this type and use the instance anywhere in the code :D

@mo8it
Copy link
Contributor Author

mo8it commented Mar 28, 2024

The proof of concept is now done! Ignore the failing tests and the missing polish, again. It is still a draft. I want @shadows-withal's approval before finishing this :)

How to try it out

  1. Run cargo install --path . in this git branch.
  2. Go into some temporary directory.
  3. Run rustlings and notice the hint about initialization.
  4. Run rustlings init
  5. A directory with the name rustlings will be created
  6. The exercises directory will be dumped from the binary into the rustlings directory and the rust-project.json Cargo.toml file will be automatically generated.
  7. Run cd rustlings to go into the generated directory
  8. Now test the commands watch, list, run, verify, reset and hint and do some exercises. Everything should work.
  9. Note that reset now dumps the exercise file from the binary. There is no git repository. The user can optionally initialize a repo like with any project.

@mo8it
Copy link
Contributor Author

mo8it commented Mar 29, 2024

I discarded the rust-project.json file. rustlings now automatically generates a Cargo.toml file on initialization. This file contains a [[bin]] entry for every exercise!

This should make things much smoother and less hacky, especially because we have many issues related to the language server.

This should also enable us to use Cargo instead of rustc to run the exercises. That would especially make Clippy exercises less of a trouble. This approach also allows us to easily add dependencies to the exercises in case we want to do so in the future.

@mo8it mo8it removed the request for review from shadows-withal March 30, 2024 15:22
@mo8it mo8it added this to the v6 milestone Mar 30, 2024
@mo8it mo8it changed the base branch from main to v6 April 4, 2024 13:24
@mo8it mo8it marked this pull request as ready for review April 4, 2024 13:32
@mo8it mo8it merged commit 8c8f30d into rust-lang:v6 Apr 4, 2024
1 check passed
@mo8it mo8it deleted the standalone-binary branch April 4, 2024 13:49
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.

Use Cargo.toml instead of rust-project.json Self-contained installation
1 participant