Skip to content

Commit

Permalink
Simplify plugin build
Browse files Browse the repository at this point in the history
  • Loading branch information
tothtamas28 committed Aug 16, 2024
1 parent 9fdb8b2 commit aaddbea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RUN apt-get update \
curl \
wget \
libcrypto++-dev \
libprocps-dev \
libsecp256k1-dev \
libssl-dev \
pandoc \
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ sudo apt-get install --yes \
curl \
wget \
libcrypto++-dev \
libprocps-dev \
libsecp256k1-dev \
libssl-dev \
python3 \
Expand All @@ -45,7 +44,7 @@ bash <(curl https://kframework.org/install)
```
Once `kup` is installed, to get the correct version of K run:
```bash
kup install k.openssl.procps.secp256k1 --version v$(cat deps/k_release)
kup install k.openssl.secp256k1 --version v$(cat deps/k_release)
```

#### Poetry
Expand Down
3 changes: 1 addition & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@
secp256k1
nixpkgs-pyk.pyk-python310
k-framework.packages.${system}.k
kmultiversx-pyk
kmultiversx-pyk
cmake
openssl.dev
clang
mpfr
pkg-config
procps
llvmPackages.llvm
];

Expand Down
37 changes: 6 additions & 31 deletions kmultiversx/src/kmultiversx/kdist/plugin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from __future__ import annotations

import shutil
import sys
from distutils.dir_util import copy_tree
from pathlib import Path
from typing import TYPE_CHECKING

from pyk.kbuild.utils import k_version, sync_files
from pyk.kbuild.utils import k_version
from pyk.kdist.api import Target
from pyk.ktool.kompile import PykBackend, kompile
from pyk.utils import run_process
from pyk.utils import run_process_2

if TYPE_CHECKING:
from collections.abc import Callable, Mapping
Expand All @@ -35,26 +34,9 @@ class PluginTarget(Target):
PLUGIN_DIR: Final = Path(__file__).parent / 'plugin'

def build(self, output_dir: Path, deps: dict[str, Any], args: dict[str, Any], verbose: bool) -> None:
sync_files(
source_dir=self.PLUGIN_DIR / 'plugin-c',
target_dir=output_dir / 'plugin-c',
file_names=[
'blake2.h',
'crypto.cpp',
'plugin_util.cpp',
'plugin_util.h',
],
)

copy_tree(str(self.PLUGIN_DIR), '.')
run_process(
['make', 'libcryptopp', 'libff', 'blake2', '-j8'],
pipe_stdout=not verbose,
)

copy_tree('./build/libcryptopp', str(output_dir / 'libcryptopp'))
copy_tree('./build/libff', str(output_dir / 'libff'))
copy_tree('./build/blake2', str(output_dir / 'blake2'))
run_process_2(['make', '-j8'])
shutil.copy('./build/krypto/lib/krypto.a', str(output_dir))

def source(self) -> tuple[Path]:
return (self.PLUGIN_DIR,)
Expand Down Expand Up @@ -86,15 +68,8 @@ def ccopts(plugin_dir: Path) -> list[str]:
'-lcrypto',
'-lsecp256k1',
'-lssl',
str(plugin_dir / 'blake2/lib/blake2.a'),
f"-I{plugin_dir / 'blake2/include'}",
str(plugin_dir / 'libcryptopp/lib/libcryptopp.a'),
f"-I{plugin_dir / 'libcryptopp/include'}",
str(plugin_dir / 'libff/lib/libff.a'),
f"-I{plugin_dir / 'libff/include'}",
str(plugin_dir / 'plugin-c/crypto.cpp'),
str(plugin_dir / 'plugin-c/plugin_util.cpp'),
] + (['-lprocps'] if sys.platform == 'linux' else [])
str(plugin_dir / 'krypto.a'),
]


return KompileTarget(
Expand Down

0 comments on commit aaddbea

Please sign in to comment.