From cfc6ae862588f5850e77da01566014c87c265660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sat, 7 Nov 2026 18:29:54 +0100 Subject: [PATCH] grading: add 2021 and 2024 editions of rust Just like the C and C++ languages have multiple standard versions, rust has editions, so add the latest two ones as two separate languages. Note, that this removes the old, unversioned, "Rust" language option. --- cms/grading/languages/rust.py | 65 ++++++++++++++++++++--------------- cmstestsuite/Tests.py | 7 ++-- setup.py | 3 +- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/cms/grading/languages/rust.py b/cms/grading/languages/rust.py index 518a2a75d6..42fca31cfe 100644 --- a/cms/grading/languages/rust.py +++ b/cms/grading/languages/rust.py @@ -21,30 +21,41 @@ from cms.grading import CompiledLanguage -__all__ = ["Rust"] - - -class Rust(CompiledLanguage): - """This defines the Rust programming language, compiled with the - standard Rust compiler available in the system. - - """ - - @property - def name(self): - """See Language.name.""" - return "Rust" - - @property - def source_extensions(self): - """See Language.source_extensions.""" - return [".rs"] - - def get_compilation_commands(self, - source_filenames, executable_filename, - for_evaluation=True): - """See Language.get_compilation_commands.""" - # In Rust only the source file containing the main function has - # to be passed to the compiler - return [["/usr/bin/rustc", "-O", "-o", - executable_filename, source_filenames[0]]] +def make_rust(edition): + class Rust(CompiledLanguage): + """This defines the Rust programming language, compiled with the + standard Rust compiler available in the system. + + """ + + @property + def name(self): + """See Language.name.""" + return f"Rust ({edition} edition)" + + @property + def source_extensions(self): + """See Language.source_extensions.""" + return [".rs"] + + def get_compilation_commands(self, + source_filenames, executable_filename, + for_evaluation=True): + """See Language.get_compilation_commands.""" + # In Rust only the source file containing the main function has + # to be passed to the compiler + return [["/usr/bin/rustc", + "--edition", edition, + "-O", + "-o", executable_filename, + source_filenames[0]]] + + return Rust + +Rust2021 = make_rust("2021") +Rust2024 = make_rust("2024") + +__all__ = [ + "Rust2021", + "Rust2024", +] diff --git a/cmstestsuite/Tests.py b/cmstestsuite/Tests.py index bf60317bea..6ce4ad3218 100644 --- a/cmstestsuite/Tests.py +++ b/cmstestsuite/Tests.py @@ -54,7 +54,8 @@ LANG_PHP = "PHP" LANG_PYTHON3 = "Python 3 / CPython" LANG_PYPY3 = "Python 3 / PyPy" -LANG_RUST = "Rust" +LANG_RUST_2021 = "Rust (2021 edition)" +LANG_RUST_2024 = "Rust (2024 edition)" LANG_C_SHARP = "C# / Mono" ALL_LANGUAGES = ( @@ -66,13 +67,13 @@ LANG_PASCAL, LANG_PHP, LANG_PYTHON3, LANG_PYPY3, - LANG_RUST, + LANG_RUST_2021, LANG_RUST_2024, ) # Languages which support compilation with a manager/grader. # TODO: this should be the same as `ALL_LANGUAGES`. MANAGER_LANGUAGES = [ - lang for lang in ALL_LANGUAGES if lang not in (LANG_HS, LANG_PHP, LANG_RUST) + lang for lang in ALL_LANGUAGES if lang not in (LANG_HS, LANG_PHP, LANG_RUST_2021, LANG_RUST_2024) ] # Languages for which solutions to be linked to a grader for communication tasks diff --git a/setup.py b/setup.py index 5d326631f4..c91c194e9d 100755 --- a/setup.py +++ b/setup.py @@ -177,7 +177,8 @@ class build_with_l10n(build): "PHP=cms.grading.languages.php:Php", "Python 3 / CPython=cms.grading.languages.python3_cpython:Python3CPython", "Python 3 / PyPy=cms.grading.languages.python3_pypy:Python3PyPy", - "Rust=cms.grading.languages.rust:Rust", + "Rust (2021 edition)=cms.grading.languages.rust:Rust2021", + "Rust (2024 edition)=cms.grading.languages.rust:Rust2024", ], }, )