Skip to content

Commit

Permalink
Fix build and cleanup Setup.hs and cabal file
Browse files Browse the repository at this point in the history
  • Loading branch information
larskuhtz committed Sep 13, 2024
1 parent 7b65a7a commit 1f1dd57
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 154 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sha2 = "0.10.8"
hex = "0.4.3"

[lib]
crate-type = ["staticlib"]
crate-type = ["staticlib", "cdylib"]

[dev-dependencies]
hex = "0.4.3"
Expand Down
101 changes: 101 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
-- This file was generated by `cargo-cabal`, its goal is to define few hooks to
-- call `cargo` on the fly and link correctly the generated library.
--
-- While it's an acceptable hack as this project is currently a prototype, this
-- should be removed before `cargo-cabal` stable release.

import Data.Maybe
import qualified Distribution.PackageDescription as PD
import Distribution.Simple
( Args
, UserHooks (confHook, preConf)
, defaultMainWithHooks
, simpleUserHooks
)
import Distribution.Simple.Program
( ghcProgram
)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo (localPkgDescr)
, buildDir
, compiler
)
import Distribution.Simple.Setup
( BuildFlags (buildVerbosity)
, ConfigFlags (configVerbosity)
, CleanFlags(..)
, fromFlag
)
import Distribution.Simple.UserHooks
( UserHooks (buildHook, confHook, cleanHook)
)
import Distribution.Simple.Utils (rawSystemExit)
import System.Directory (getCurrentDirectory)
import Distribution.Text (display)
import Distribution.Simple.Compiler
import Distribution.System (buildPlatform)
import Distribution.Simple.BuildPaths
( mkGenericSharedBundledLibName
, mkGenericStaticLibName
)

main :: IO ()
main =
defaultMainWithHooks
simpleUserHooks
{ buildHook = rustBuildHook
, cleanHook = rustCleanHook
}

rustCleanHook
:: PD.PackageDescription
-> ()
-> UserHooks
-> CleanFlags
-> IO ()
rustCleanHook desc () hooks flags = do
pwd <- getCurrentDirectory
putStrLn $ "cleanup rust build artifacts: delete " <> pwd <> "/target"
rawSystemExit (fromFlag $ cleanVerbosity flags) "rm" ["-r", "./target"]
cleanHook simpleUserHooks desc () hooks flags

rustBuildHook
:: PD.PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BuildFlags
-> IO ()
rustBuildHook description localBuildInfo hooks flags = do
-- run Rust build
-- FIXME add cargo and rust to program db during configure step
-- FIXME: add `--target $TARGET` flag to support cross-compiling to $TARGET
putStrLn "Call `cargo build --release` to build a dependency written in Rust"
rawSystemExit (fromFlag $ buildVerbosity flags) "cargo" ["build","--release"]

-- copy static lib
putStrLn $ "Copy libplonk_verify.a to " <> staticTarget
rawSystemExit (fromFlag $ buildVerbosity flags) "cp"
[ "target/release/libplonk_verify.a"
, staticTarget
]

-- copy dyn lib
putStrLn $ "Copy libplonk_verify.dylib to " <> dynTarget
rawSystemExit (fromFlag $ buildVerbosity flags) "cp"
[ "target/release/libplonk_verify.dylib"
, dynTarget
]

putStrLn "rustc compilation succeeded"
buildHook simpleUserHooks description localBuildInfo hooks flags
where
targetLibname = "Cplonk_verify"
c = compiler localBuildInfo
ghcVersion = display (compilerFlavor c) <> display (compilerVersion c)
staticTarget = buildDir localBuildInfo
<> "/"
<> mkGenericStaticLibName targetLibname
dynTarget = buildDir localBuildInfo
<> "/"
<> mkGenericSharedBundledLibName buildPlatform (compilerId c) targetLibname

81 changes: 0 additions & 81 deletions Setup.lhs

This file was deleted.

99 changes: 27 additions & 72 deletions plonk-verify.cabal
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
cabal-version: 2.4
-- The cabal-version field refers to the version of the .cabal specification,
-- and can be different from the cabal-install (the tool) version and the
-- Cabal (the library) version you are using. As such, the Cabal (the library)
-- version used must be equal or greater than the version stated in this field.
-- Starting from the specification version 2.2, the cabal-version field must be
-- the first thing in the cabal file.

-- Initial package description generated by 'cabal init'. For further
-- documentation, see: http://haskell.org/cabal/users-guide/
--
-- The name of the package.
name: plonk-verify

-- The package version.
-- See the Haskell package versioning policy (PVP) for standards
-- guiding when and how versions should be incremented.
-- https://pvp.haskell.org
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0
cabal-version: 3.0
name: plonk-verify
version: 0.1.0

-- A short (one-line) description of the package.
-- synopsis:

-- A longer description of the package.
-- description:

-- The license under which the package is released.
-- license:
license: MIT

-- The package author(s).
-- author:
Expand All @@ -37,69 +17,44 @@ version: 0.1.0
-- patches.
-- maintainer:

-- A copyright notice.
-- copyright:
copyright: Copyright (c) 2024 Argument Computer Corporation

extra-source-files: Cargo.toml Cargo.lock src/lib.rs
extra-doc-files:
README.md

extra-source-files:
Cargo.toml
Cargo.lock
src/lib.rs
hsbindgen.toml

data-files:
verifier-assets/v1.0.8-testnet/vk.bin

-- This let us hook Cabal steps to Setup.lhs script.
build-type: Custom
build-type: Custom
custom-setup
setup-depends: Cabal, base, directory, process

-- Extra doc files to be distributed with the package, such as a CHANGELOG or a
-- README.
-- extra-doc-files:

-- Extra source files to be distributed with the package, such as examples, or
-- a tutorial module.
-- extra-source-files:
--
-- FIXME: It's still unclear to me what would be the best strategy to let users
-- publish packages generated by `cargo-cabal` on Hackage. While it is pretty
-- hazardous to put Rust code in sdist archive (because that would require that
-- the library end-user have a Rust developer environment on this machine and
-- that wouldn't play well with cross-compilation), is it a good idea to
-- package generated platform-dependent library as source?
setup-depends:
, Cabal
, base
, directory
, process

common warnings
ghc-options: -Wall

library
-- Import common warning flags.
import: warnings

-- Modules exported by the library.
exposed-modules: PlonkVerify

-- Modules included in this library but not exported.
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

-- Other library packages from which modules are imported.
build-depends: base

-- Directories containing source files.
hs-source-dirs: src

-- Base language which the package is written in.
import: warnings
default-language: Haskell2010
extra-libraries:
plonk_verify
hs-source-dirs: src
exposed-modules:
PlonkVerify
build-depends:
base
frameworks:
CoreFoundation
Security

-- This file was generated by `cargo-cabal`, but please don't hesitate to edit it!

-- We would rather rely on `cabal init --non-interactive` to generate this file
-- but there is no CLI arg to set `build-type: Custom` on which it sadly
-- currently have to rely on.
extra-bundled-libraries:
Cplonk_verify

test-suite tests
import: warnings
Expand Down

0 comments on commit 1f1dd57

Please sign in to comment.