Skip to content

Commit

Permalink
Using foreign-library stanza
Browse files Browse the repository at this point in the history
  • Loading branch information
td202 committed Jan 18, 2024
1 parent ee69d58 commit ce83a27
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
61 changes: 48 additions & 13 deletions concordium-consensus/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,59 @@ library:

extra-libraries: concordium_smart_contract_engine

# when:
# - condition: os(windows)
# then:
# #ghc-options: -threaded -static -shared lib.def -L../concordium-base/smart-contracts/lib -lconcordium_smart_contract_engine
# ghc-options: -threaded
# else:
# # -fPIC casues issues on Windows: https://gitlab.haskell.org/ghc/ghc/-/issues/24016
# # However, it should not do anything on Windows anyway, so it's fine not to enable it there.
# ghc-options: -fPIC
# when:
# - condition: flag(dynamic)
# then:
# ghc-options: -shared -dynamic
# else:
# ghc-options: -static
when:
- condition: os(windows)
then:
ghc-options: -threaded -static -shared lib.def -L../concordium-base/smart-contracts/lib -lconcordium_smart_contract_engine
else:
# -fPIC casues issues on Windows: https://gitlab.haskell.org/ghc/ghc/-/issues/24016
# However, it should not do anything on Windows anyway, so it's fine not to enable it there.
ghc-options: -fPIC
when:
- condition: flag(dynamic)
then:
ghc-options: -shared -dynamic
else:
ghc-options: -static
- condition: "!(os(windows)) && !(flag(dynamic))"
ghc-options: -fPIC -static
src-dirs: src-lib

# Other options might be needed, such has -dynamic -lHSrts or -lHSrts-ghc8.4.3
# Possibly this depends on the platform

verbatim: |
foreign-library concordium-consensus-lib
type: native-shared
if os(Windows)
options: standalone
mod-def-file: lib.def
ghc-options: -threaded
else
ghc-options; -fPIC
other-modules:
Concordium.External
Concordium.External.DryRun
Concordium.External.Helpers
Concordium.External.GRPC2
hs-source-dirs: src-lib
build-depends: aeson, proto-lens, cereal, containers, transformers, vector, microlens-platform, directory, filepath, base, text, bytestring, concordium-consensus, concordium-base
default-language: Haskell2010
default-extensions:
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GeneralizedNewtypeDeriving
KindSignatures
LambdaCase
MultiParamTypeClasses
RecordWildCards
TupleSections
TypeOperators
executables:
Concordium-exe:
main: Main.hs
Expand Down
7 changes: 2 additions & 5 deletions concordium-node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,11 @@ const DYLIB_EXTENSION: &str = "dylib";

#[cfg(all(not(feature = "static"), not(windows)))]
/// Link with Haskell runtime libraries.
/// The RTS version defaults to the threaded one, but can be overridded by the
/// The RTS version defaults to the threaded one, but can be overridden by the
/// HASKELL_RTS_VARIANT environment variable
fn link_ghc_libs() -> std::io::Result<std::path::PathBuf> {
let rts_variant =
env::var("HASKELL_RTS_VARIANT").unwrap_or_else(|_| "libHSrts_thr-".to_owned());
env::var("HASKELL_RTS_VARIANT").unwrap_or_else(|_| "libHSrts-1.0.2_thr-".to_owned());
let ghc_lib_dir = env::var("HASKELL_GHC_LIBDIR").unwrap_or_else(|_| {
command_output(Command::new("stack").args([
"--stack-yaml",
Expand All @@ -733,9 +733,6 @@ fn link_ghc_libs() -> std::io::Result<std::path::PathBuf> {
"--print-libdir",
]))
});
#[cfg(all(not(feature = "static"), target_os = "linux"))]
let rts_dir = Path::new(&ghc_lib_dir).join("rts");
#[cfg(all(not(feature = "static"), target_os = "macos"))]
let rts_dir = Path::new(&ghc_lib_dir).join(GHC_VARIANT);
println!("cargo:rustc-link-search=native={}", rts_dir.to_string_lossy());
for item in std::fs::read_dir(&rts_dir)?.filter_map(Result::ok) {
Expand Down

0 comments on commit ce83a27

Please sign in to comment.