Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 38 additions & 27 deletions cms/grading/languages/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
7 changes: 4 additions & 3 deletions cmstestsuite/Tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
},
)
Loading