{"id":16507601,"url":"https://github.com/chmp/cargo-wop","last_synced_at":"2025-03-23T13:32:15.452Z","repository":{"id":57540949,"uuid":"289997619","full_name":"chmp/cargo-wop","owner":"chmp","description":"Run cargo on Rust source files without setting up a project","archived":false,"fork":false,"pushed_at":"2023-05-15T17:48:32.000Z","size":235,"stargazers_count":1,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T01:40:31.504Z","etag":null,"topics":["build-tool","cargo","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chmp.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-24T17:43:25.000Z","updated_at":"2023-12-17T00:15:54.000Z","dependencies_parsed_at":"2024-10-28T16:15:02.771Z","dependency_job_id":null,"html_url":"https://github.com/chmp/cargo-wop","commit_stats":{"total_commits":72,"total_committers":1,"mean_commits":72.0,"dds":0.0,"last_synced_commit":"9594b9860c41c1b086e8263549dd896afeedc4aa"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Fcargo-wop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Fcargo-wop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Fcargo-wop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chmp%2Fcargo-wop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chmp","download_url":"https://codeload.github.com/chmp/cargo-wop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244305965,"owners_count":20431736,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-tool","cargo","rust"],"created_at":"2024-10-11T15:29:18.506Z","updated_at":"2025-03-23T13:32:15.113Z","avatar_url":"https://github.com/chmp.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cargo-wop` - cargo without project\n\n[How arguments are interpreted](#how-arguments-are-interpreted)\n| [Configuration](#configuration)\n| [Development tasks](#development-tasks)\n| [VS Code build commands](#vs-code-build-commands)\n| [Related projects](#related-projects)\n\nRust source files as self-contained projects. `cargo-wop` allows `cargo`to work\nwith rust source file as if thy were full projects. This project is heavily\ninspired by [cargo-script][cargo-script], [cargo-eval][cargo-eval]. In contrast\nto these projects, `cargo-wop` is designed to be as close as possible to cargo\nand support all sensible subcommands.\n\nRun a file as a script:\n\n```bash\ncargo wop my-script.rs\n\n# equivalent call:\ncargo wop run my-script.rs\n```\n\nBuild artifacts defined in the script:\n\n```\ncargo wop build my-script.rs\n```\n\nRun tests defined in the script:\n\n```\ncargo wop test my-script.rs\n```\n\n## How arguments are interpreted\n\nFor most commands `cargo-wop` rewrites the command line as follows:\n\n```bash\n# Original command-line\ncargo wop [cargo-command] [script] [args...]\n\n# Rewritten command line\ncargo [cargo-command] --manifest-path [generated_manifest] [args...]\n```\n\nThe manifest path points to a Cargo.toml file written to the project director in\n`\"~/.cargo/wop-cache/\"`. The project directory will also contain the `target`\nfolder.\n\nAt the moment the following cargo commands are supported: `bench`, `build`,\n`check`, `clean`, `clippy`, `fmt`, `install`, `locate-project`, `metadata`,\n`pkgid`, `run`, `tree`, `test`, `verify-project`.\n\nSome commands use additional rules:\n\n- `new`: create a new source file based on templates. Run `cargo wop new` to get\n  a list of all available templates. Run `cargo wop new TEMPLATE SOURCE.rs` to\n  create the file. For example use `cargo wop new --lib SOURCE.rs` to create a\n  shared library\n- `run`: all arguments are passed per default to the script, not to cargo. To\n  pass arguments to `cargo` place them before a `--`. For example: `cargo wop\n  run my-script.rs --verbose -- ...`\n- `build`: is executed twice. Once to build the package and a second time to\n  determine the generated build artifacts and copy them into the local folder\n- `build` and `run` default to release builds. To disable this behavior, use the\n  `build-debug` and `run-debug` commands\n- `install`: no manifest path is added, but the `--path` argument to the\n  manifest directory\n\nCustom commands:\n\n- `manifest`: print out the generated manifest\n- `write-manifest`: write the manifest into the current working directory\n\nIf no command is specified, the default command is executed, `run` without\nadditional configuration.\n\n## Configuration\n\n[Specifying dependencies](#specifying-dependencies)\n| [Building libraries](#building-libraries)\n| [Default actions](#default-actions)\n| [File filters](#file-filters)\n| [Build scripts](#build-scripts)\n\n### Specifying dependencies\n\nDependencies are described in a cargo manifest embedded in the top-level\ncomment. Importantly, the file must start with the comment for the manifest to\nbe recognized. For example:\n\n```rust\n//! ```cargo\n//! [dependencies]\n//! serde = \"1.0\"\n//! ```\n```\n\nDependencies can also be local paths relative to the script file by using the\nstandard cargo syntax:\n\n```rust\n//! ```cargo\n//! [dependencies]\n//! local_dep = { path = \"./local_dep\" }\n//! ```\n```\n\n### Building libraries\n\nThe embedded manifest can contain any keys recognized by cargo. `cargo-wop`\nnormalizes this manifest and makes sure the source file is correctly included.\nIt also normalizes any paths used to specify dependencies. To show the generated\nmanifest use:\n\n```bash\ncargo wop manifest my-script.rs\n```\nFor example, simply specify a `[lib]` target with the correct flags set to build\na static C library:\n\n```rust\n//! My script\n//!\n//! ```cargo\n//! [lib]\n//! crate-type = [\"cdylib\"]\n//!\n//! [dependencies]\n//! ```\n```\n\nThis script can be built into a library via:\n\n```bash\ncargo wop build my-script.rs\n```\n\n### Default actions\n\nThe default action can be configured by setting the `\"default-action\"` array in\nthe embedded manifest file:\n\n```rust\n//! ```cargo\n//! [cargo-wop]\n//! default-action = [COMMAND, ..ARGS]\n//! ```\n```\n\nIt is interpreted as `COMMAND FILE ..ARGS ..CLI_ARGS`, where `CLI_ARGS` are the\narguments passed via the command line. Without configuration, it corresponds to\n`default-action = [\"run\"]`. For example, to build the given file as a wasm32\nlibrary configure it as\n\n```\n//! ```cargo\n//! [cargo-wop]\n//! default-action = [\"build\", \"--target\", \"wasm32-unknown--unknown\"]\n//! ```\n```\n\n### File filters\n\nFor some applications it is helpful to rename the generated files. For example\nPyO3 extensions need to be stripped of their \"lib\" prefix on Linux systems.\nCargo wop supports renaming files by specifying a filter dictionary\n\n```rust\n//! [cargo-wop]\n//! filter = {  \"libexample.so\" = \"example.so\" }\n//! ```\n```\n\nTo not copy files into the current directory, map them to an empty string. For\nexample, to not copy the debug information on Windows, use\n\n```rust\n//! [cargo-wop]\n//! filter = {  \"example.pdb\" = \"\" }\n//! ```\n```\n\nThe files that are specified in the mapping do not need to be part of the build.\nTherefore, it is safe to include platform specific renames even in\ncross-platform files.\n\n### Build scripts\n\n[Build scripts][build-scripts] can be configured by setting the `package.build`\nkey to a script relative to the source file. For example:\n\n```rust\n//! [package]\n//! build = \"example_build.rs\"\n```\n\nNote, that cargo executes the build script in the generated project directory in\nwhich the manifest is found, not the directory containing the script. One option,\nto use paths relative to the build script, is to change the directory at the\nstart of the build script. Using the standard [`file!()`][file-macro] macro:\n\n```rust\nfn main() {\n    let self_path = std::path::PathBuf::from(file!());\n    std::env::set_current_dir(self_path.parent().unwrap()).unwrap();\n\n    // ...\n}\n```\n\n[build-scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html\n[file-macro]: https://doc.rust-lang.org/stable/std/macro.file.html\n\n# VS Code build commands\n\nTo setup cargo wop as build command in VS Code, that can be accessed via\n\"Ctrl-Shift-B\", create the file `.vscode/tasks.json` with the following\ncontents:\n\n```json\n{\n    \"version\": \"2.0.0\",\n    \"tasks\": [\n        {\n            \"label\": \"cargo wop\",\n            \"type\": \"process\",\n            \"command\": \"cargo\",\n            \"args\": [\"wop\", \"${file}\"],\n            \"group\": \"build\",\n            \"options\": {\"cwd\": \"${fileDirname}\"},\n            \"problemMatcher\": [\"$rustc\"],\n            \"presentation\": {\"focus\": true}\n        },\n        {\n            \"label\": \"cargo wop [task]\",\n            \"type\": \"process\",\n            \"command\": \"cargo\",\n            \"args\": [\"wop\", \"${input:task}\", \"${file}\"],\n            \"group\": \"build\",\n            \"options\": {\"cwd\": \"${fileDirname}\"},\n            \"problemMatcher\": [\"$rustc\"],\n            \"presentation\": {\"focus\": true}\n        }\n    ],\n    \"inputs\": [\n        {\n          \"type\": \"pickString\",\n          \"id\": \"task\",\n          \"description\": \"What task to run?\",\n          \"options\": [\n            \"build\",\n            \"clippy\",\n            \"clean\",\n            \"fmt\",\n            \"install\",\n            \"test\",\n            \"run\"\n          ],\n          \"default\": \"fmt\"\n        }\n      ]\n}\n```\n\nThe `task.json` is documented [here][task-json]. Now pressing \"Ctrl-Shift-B\" and\nselecting cargo wop will execute the currently opened file using cargo wop.\n\n[task-json]: https://go.microsoft.com/fwlink/?LinkId=733558\n\n# Development tasks\n\nCommon tasks are bundled in the `make.rs` script. It can be used with\n`cargo-wop` itself. First install `cargo-wop`. Then run the `make.rs` script:\n\n```bash\ncargo install --path .\ncargo wop make.rs precommit\n```\n\nRun `cargo wop make.rs help` to a see a list of available commands.\n\n# Related projects\n\n- [cargo-script][cargo-script] and forks of it [cargo-scripter][cargo-scripter],\n  [cargo-eval][cargo-eval]\n- [cargo-play][cargo-play]\n- [cargo-temp][cargo-temp]\n\n[cargo-script]: https://github.com/DanielKeep/cargo-script\n[cargo-eval]: https://github.com/reitermarkus/cargo-eval\n[cargo-play]: https://github.com/fanzeyi/cargo-play\n[cargo-scripter]: https://github.com/artemshein/cargo-script\n[cargo-temp]: https://github.com/yozhgoor/cargo-temp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchmp%2Fcargo-wop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchmp%2Fcargo-wop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchmp%2Fcargo-wop/lists"}