From d258bed574d4f6fce54d021cc909681ac197d51c Mon Sep 17 00:00:00 2001 From: Dan Vargas Date: Mon, 7 Feb 2022 10:56:17 -0700 Subject: [PATCH] add nasm and nasm64 --- packages/nasm/2.15.5/build.sh | 21 ----------- packages/nasm/2.15.5/compile | 21 ----------- packages/nasm/2.15.5/environment | 4 --- packages/nasm/2.15.5/metadata.json | 14 -------- packages/nasm/2.15.5/run | 5 --- packages/nasm/2.15.5/test.nasm.asm | 16 --------- packages/nasm/2.15.5/test.nasm64.asm | 18 ---------- runtimes/default.nix | 2 ++ runtimes/nasm-nasm64.nix | 54 ++++++++++++++++++++++++++++ runtimes/nasm.nix | 52 +++++++++++++++++++++++++++ 10 files changed, 108 insertions(+), 99 deletions(-) delete mode 100755 packages/nasm/2.15.5/build.sh delete mode 100644 packages/nasm/2.15.5/compile delete mode 100644 packages/nasm/2.15.5/environment delete mode 100644 packages/nasm/2.15.5/metadata.json delete mode 100644 packages/nasm/2.15.5/run delete mode 100644 packages/nasm/2.15.5/test.nasm.asm delete mode 100644 packages/nasm/2.15.5/test.nasm64.asm create mode 100644 runtimes/nasm-nasm64.nix create mode 100644 runtimes/nasm.nix diff --git a/packages/nasm/2.15.5/build.sh b/packages/nasm/2.15.5/build.sh deleted file mode 100755 index 0f39f6f..0000000 --- a/packages/nasm/2.15.5/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -# Put instructions to build your package in here -PREFIX=$(realpath $(dirname $0)) - -mkdir -p build - -cd build - -curl -L "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.gz" -o nasm.tar.gz - -tar xzf nasm.tar.gz --strip-components=1 - -# === autoconf based === -./configure --prefix "$PREFIX" - -make -j$(nproc) -make install -j$(nproc) -cd ../ -rm -rf build - diff --git a/packages/nasm/2.15.5/compile b/packages/nasm/2.15.5/compile deleted file mode 100644 index f133a67..0000000 --- a/packages/nasm/2.15.5/compile +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -# Put instructions to compile source code, remove this file if the language does not require this stage - - -case "${PISTON_LANGUAGE}" in - nasm) - nasm -f elf32 -o binary.o "$@" - ld -m elf_i386 binary.o -o binary - ;; - nasm64) - nasm -f elf64 -o binary.o "$@" - ld -m elf_x86_64 binary.o -o binary - ;; - *) - echo "How did you get here? (${PISTON_LANGUAGE})" - exit 1 - ;; -esac - -chmod +x ./binary \ No newline at end of file diff --git a/packages/nasm/2.15.5/environment b/packages/nasm/2.15.5/environment deleted file mode 100644 index 780b668..0000000 --- a/packages/nasm/2.15.5/environment +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -# Put 'export' statements here for environment variables -export PATH=$PWD/bin:$PATH diff --git a/packages/nasm/2.15.5/metadata.json b/packages/nasm/2.15.5/metadata.json deleted file mode 100644 index 80a5150..0000000 --- a/packages/nasm/2.15.5/metadata.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "language": "nasm", - "version": "2.15.5", - "provides": [ - { - "language": "nasm", - "aliases": ["asm", "nasm32"] - }, - { - "language": "nasm64", - "aliases": ["asm64"] - } - ] -} diff --git a/packages/nasm/2.15.5/run b/packages/nasm/2.15.5/run deleted file mode 100644 index f910a1c..0000000 --- a/packages/nasm/2.15.5/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -# Put instructions to run the runtime -shift -./binary "$@" diff --git a/packages/nasm/2.15.5/test.nasm.asm b/packages/nasm/2.15.5/test.nasm.asm deleted file mode 100644 index d1e5a57..0000000 --- a/packages/nasm/2.15.5/test.nasm.asm +++ /dev/null @@ -1,16 +0,0 @@ -SECTION .DATA -good: db 'OK',10 -txtlen: equ $-good - -SECTION .TEXT -GLOBAL _start - -_start: -mov eax,4 -mov ebx,1 -mov ecx,good -mov edx,txtlen -int 80h -mov eax,1 -mov ebx,0 -int 80h \ No newline at end of file diff --git a/packages/nasm/2.15.5/test.nasm64.asm b/packages/nasm/2.15.5/test.nasm64.asm deleted file mode 100644 index 20ea316..0000000 --- a/packages/nasm/2.15.5/test.nasm64.asm +++ /dev/null @@ -1,18 +0,0 @@ -SECTION .data - good: db "OK", 0x0 - txtlen: equ $ - good - -SECTION .text -GLOBAL _start - -_start: - ;sys_write - mov rax, 1 - mov rdi, 1 - mov rsi, good - mov rdx, txtlen - syscall - ;sys_exit - mov rax, 60 - mov rdi, 0 - syscall \ No newline at end of file diff --git a/runtimes/default.nix b/runtimes/default.nix index 478b0fd..f7b30c3 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -31,4 +31,6 @@ args: { "octave" = import ./octave.nix args; "ocaml" = import ./ocaml.nix args; "nim" = import ./nim.nix args; + "nasm" = import ./nasm.nix args; + "nasm-nasm64" = import ./nasm-nasm64.nix args; } diff --git a/runtimes/nasm-nasm64.nix b/runtimes/nasm-nasm64.nix new file mode 100644 index 0000000..5a10d2b --- /dev/null +++ b/runtimes/nasm-nasm64.nix @@ -0,0 +1,54 @@ +{pkgs, piston, ...}: +let + pkg = pkgs.nasm; + binutils = pkgs.binutils; +in piston.mkRuntime { + language = "nasm64"; + version = pkg.version; + runtime = "nasm"; + + aliases = [ + "asm64" + ]; + + compile = '' + ${pkg}/bin/nasm -f elf64 -o binary.o "$@" + ${binutils}/bin/ld -m elf_x86_64 binary.o -o binary + ''; + + run = '' + shift + ./binary "$@" + ''; + + tests = [ + (piston.mkTest { + files = { + "test.asm64" = '' + SECTION .data + good: db "OK", 10 + txtlen: equ $ - good + + SECTION .text + GLOBAL _start + + _start: + ;sys_write + mov rax, 1 + mov rdi, 1 + mov rsi, good + mov rdx, txtlen + syscall + ;sys_exit + mov rax, 60 + mov rdi, 0 + syscall + ''; + }; + args = []; + stdin = ""; + packages = []; + main = "test.asm64"; + }) + ]; +} \ No newline at end of file diff --git a/runtimes/nasm.nix b/runtimes/nasm.nix new file mode 100644 index 0000000..486d1f4 --- /dev/null +++ b/runtimes/nasm.nix @@ -0,0 +1,52 @@ +{pkgs, piston, ...}: +let + pkg = pkgs.nasm; + binutils = pkgs.binutils; +in piston.mkRuntime { + language = "nasm"; + version = pkg.version; + + aliases = [ + "nasm32" + "asm" + ]; + + compile = '' + ${pkg}/bin/nasm -f elf32 -o binary.o "$@" + ${binutils}/bin/ld -m elf_i386 binary.o -o binary + ''; + + run = '' + shift + ./binary "$@" + ''; + + tests = [ + (piston.mkTest { + files = { + "test.asm" = '' + SECTION .DATA + good: db 'OK',10 + txtlen: equ $-good + + SECTION .TEXT + GLOBAL _start + + _start: + mov eax,4 + mov ebx,1 + mov ecx,good + mov edx,txtlen + int 80h + mov eax,1 + mov ebx,0 + int 80h + ''; + }; + args = []; + stdin = ""; + packages = []; + main = "test.asm"; + }) + ]; +} \ No newline at end of file