Skip to content

Latest commit

 

History

History
223 lines (143 loc) · 9.41 KB

cheatsheet.md

File metadata and controls

223 lines (143 loc) · 9.41 KB

risundle cheatsheet

English | 日本語

A task-oriented quick reference: find what you want to do, copy the command, done. See the README for what each feature is, and spec.md for the fine details.

One-time setup

Install

cargo install risundle

(Requires the Rust toolchain and a C++ compiler such as g++.)

Make your own library available

risundle library add mylib ~/cp/library

mylib is any ID you like; ~/cp/library is the library root (the directory your includes are relative to). No need to register the standard library — it is registered automatically on the first bundle.

Make third-party libraries like AC Library available

Just add them the same way.

risundle library add ac-library ~/ac-library

Every time you submit

Bundle a solution into a single file for submission

risundle main.cpp > submission.cpp

You get a submission.cpp where, out of your libraries, only the header files main.cpp actually uses remain. Paste it into the judge and you are done.

Copy straight to the clipboard without creating a file

risundle main.cpp | clip.exe                    # Windows / WSL (ASCII-only sources)
risundle main.cpp | iconv -t cp932 | clip.exe   # WSL on Japanese Windows (see below)
risundle main.cpp | pbcopy                      # macOS
risundle main.cpp | xclip -sel clip             # Linux (X11)
risundle main.cpp | wl-copy                     # Linux (Wayland)

Caution on WSL: clip.exe interprets its input in the Windows system code page, not UTF-8. If your code contains non-ASCII comments, they get garbled — and line breaks can even disappear, silently changing what the code means. Convert first with iconv -t <your code page> as shown above (cp932 on Japanese Windows).

Run tests and submit in one go (combine with oj)

To keep its responsibilities small, risundle itself has no test or submit features. Chain it with existing tools such as oj using &&.

# If the samples pass, bundle and submit right away
oj t && risundle main.cpp > submission.cpp && oj s submission.cpp

&& runs the next command only if the previous one succeeded, so a failing sample never reaches the submit step.

Tweaking the submission file

Leave a library the judge already has as #include, unexpanded

Example: the judge provides AC Library, so you don't want it embedded.

risundle -k ac-library main.cpp > submission.cpp

-k takes the ID you used at registration. -k is additive, so std stays kept by default. Also write the includes in your solution with angle brackets like #include <atcoder/dsu>, not #include "..." (with "..." the keep may not take effect).

Expand a kept library just this once

risundle --no-keep ac-library main.cpp > submission.cpp

--no-keep beats both the config file and -k, so the library gets expanded.

Process with the same compiler and flags as the judge

risundle -c clang++ main.cpp -- -std=gnu++20 -O2

-c switches the compiler; everything after -- is passed to the compiler as is. Useful when your code branches on compilers or flags with #ifdef.

Verify it compiles before submitting (automatic fallback)

Tree-shaking is an approximation, so on rare occasions it can drop a needed definition. How to fall back on failure differs per person, so risundle itself has no automatic fallback — you compose it in the shell instead. To test-compile the bundle and switch to full expansion (--no-tree-shaking) when it fails, chain with || (which runs the next command only if the previous one failed).

risundle main.cpp > submission.cpp
g++ -std=gnu++20 -o /dev/null submission.cpp ||
  risundle --no-tree-shaking main.cpp > submission.cpp

Going all the way through linking also catches undefined references when only a definition got dropped (the binary itself is not needed, so it is discarded to -o /dev/null). Match the flags to your judge. Also, if you keep a library other than std, its #include is invisible to plain g++ — tell it where the library lives with -I ~/ac-library or similar (otherwise the check always fails and the fallback fires every time).

If that is too much to type every time, put a function in your shell config (~/.bashrc etc.).

bundle() {
  risundle "$1" > submission.cpp &&
    g++ -std=gnu++20 -o /dev/null submission.cpp ||
    { echo 'verification failed; falling back to full expansion' >&2 &&
      risundle --no-tree-shaking "$1" > submission.cpp; }
}

From then on, bundle main.cpp is all you need. When the fallback fires, check the g++ error printed right above it: a mistake in your own code means the fallback output won't compile either, while an undefined reference to a dropped definition means tree-shaking missed something — a report in the issues would be much appreciated.

Keep the original source as a comment at the top of the submission

risundle -e main.cpp > submission.cpp

For judges that publish submissions, when you want readers to see the source exactly as you wrote it. If your config file sets embed = true, cancel it for one run with --no-embed.

After touching a library

Reflect changes after editing a library

risundle library update mylib   # just one
risundle library update         # everything registered

Even if you forget, bundling stops with a "library changed" error to remind you — just run it then.

Check what is registered

risundle library list           # IDs, kinds, and paths
risundle library show mylib     # details
risundle library show mylib -v  # down to which file defines which identifiers

When tree-shaking output is not what you expected, -v tells you which file each identifier comes from.

Check whether your library is compatible with risundle

risundle only supports libraries with reasonably well-behaved file layouts. See compatibility.md for the exact conditions. For example, splitting a scope across files or generating declaration names with macros (X-macros) is unsupported.

Unregister

risundle library delete mylib

Resolve the standard library with compilers other than g++

risundle library add-std clang++

Each call adds another compiler to the set, so register both g++ and clang++ and switch with -c.

Tired of typing the same options

Put a .risundlerc.toml in the directory of your solutions (or a parent, e.g. the project root) and it applies to every bundle underneath.

[compiler]
path = "g++"
options = ["-std=gnu++20", "-O2", "-DONLINE_JUDGE", "-DATCODER"]

[library]
keep = ["std", "ac-library"]

CLI options take precedence when both are given (-k adds to the configured keeps, and options after -- are appended to the configured ones). Add --no-config to ignore the file entirely.

When you write keep yourself, list "std" alongside the rest. Forget it and the standard library gets expanded too (risundle prints a warning when that happens).

When things go wrong

Bundling stops saying the library has changed

The library contents changed after registration. Reflecting the change is the proper fix; skip verification if you are in a hurry.

risundle library update            # proper fix
risundle -n main.cpp               # quick and dirty (skips verification)

The bundled file fails to compile

Turn off tree-shaking (everything except kept libraries gets expanded) — that gets you something submittable for now.

risundle --no-tree-shaking main.cpp > submission.cpp

If this fixes it, tree-shaking dropped a needed definition. The known gap is implementation files whose target cannot be determined statically (e.g. files defining only free-function operators); anything else would be much appreciated as a report in the issues. To automate this switch, see "Verify it compiles before submitting". If it still fails, the cause lies outside tree-shaking — trace it directly from the compiler error message.

A library you passed to -k gets expanded anyway

If a warning about unregistered libraries is printed, the ID does not match any registered name — check with risundle library list (or register it with risundle library add if you haven't yet).

If there is no warning, are you writing the include as #include "atcoder/dsu"? Switch to the angle-bracket form #include <atcoder/dsu>.

The standard library got expanded too

std is missing from the effective keeps. The typical cause is a config file whose keep forgets to list "std" (writing keep yourself replaces the default). Add "std" to keep in .risundlerc.toml. risundle also prints a warning in this situation.

Error line numbers don't match the original file

The bundled file contains #line directives, so compiler diagnostics point at the original files. Read error line numbers on the judge as referring to your original file too.