diff --git a/.github/workflows/bindings_haskell.yml b/.github/workflows/bindings_haskell.yml index acb105300e1f..f236ecf62c6a 100644 --- a/.github/workflows/bindings_haskell.yml +++ b/.github/workflows/bindings_haskell.yml @@ -62,7 +62,7 @@ jobs: - name: Build & Test working-directory: "bindings/haskell" run: | - LD_LIBRARY_PATH=../../target/debug cabal test + cabal test - name: Save haskell cache uses: actions/cache/save@v3 with: diff --git a/bindings/haskell/CONTRIBUTING.md b/bindings/haskell/CONTRIBUTING.md index 2cdb28ada391..065a5894a6f0 100644 --- a/bindings/haskell/CONTRIBUTING.md +++ b/bindings/haskell/CONTRIBUTING.md @@ -39,17 +39,16 @@ To verify that everything is working properly, run `ghc -V` and `cabal -V`: ```shell > ghc -V -The Glorious Glasgow Haskell Compilation System, version 9.6.1 +The Glorious Glasgow Haskell Compilation System, version 9.2.8 > cabal -V -cabal-install version 3.10.1.0 -compiled using version 3.10.1.0 of the Cabal library +cabal-install version 3.6.2.0 +compiled using version 3.6.2.0 of the Cabal library ``` ## Build ```shell -cargo build -LIBRARY_PATH=../../target/debug cabal build +cabal build ``` To clean up the build: @@ -64,7 +63,7 @@ cabal clean We use [`tasty`](https://hackage.haskell.org/package/tasty) as the test framework. To run the tests: ```shell -LD_LIBRARY_PATH=../../target/debug cabal test +cabal test ``` ```text @@ -85,20 +84,3 @@ cabal haddock ``` If your `cabal` version is greater than `3.8`, you can use `cabal haddock --open` to open the documentation in your browser. Otherwise, you can visit the documentation from `dist-newstyle/build/$ARCH/ghc-$VERSION/opendal-$VERSION/doc/html/opendal/index.html`. - -## Misc - -If you don't want to specify `LIBRARY_PATH` and `LD_LIBRARY_PATH` every time, you can use [`direnv`](https://direnv.net/) to set the environment variable automatically. Add the following to your `.envrc`: - -```shell -export LIBRARY_PATH=../../target/debug:$LIBRARY_PATH -export LD_LIBRARY_PATH=../../target/debug:$LD_LIBRARY_PATH -``` - -If you are using [`Haskell`](https://marketplace.visualstudio.com/items?itemName=haskell.haskell) in VSCode, you may need to add the following configuration to your `settings.json`: - -```json -"haskell.serverEnvironment": { - "LIBRARY_PATH": "../../target/debug:$LIBRARY_PATH" -}, -``` diff --git a/bindings/haskell/README.md b/bindings/haskell/README.md index fac856aad562..e522e4ab69a6 100644 --- a/bindings/haskell/README.md +++ b/bindings/haskell/README.md @@ -35,24 +35,14 @@ main = do ## Build -1. Build OpenDAL Haskell Interface - -```bash -cargo build --package opendal-hs -``` - -2. Build Haskell binding - -If you don't want to install `libopendal_hs`, you need to specify library path manually by `LIBRARY_PATH=${OPENDAL_ROOT}/target/debug`. - ```bash -LIBRARY_PATH=... cabal build +cabal build ``` ## Test ```bash -LD_LIBRARY_PATH=... cabal test +cabal test ``` ## Doc diff --git a/bindings/haskell/Setup.hs b/bindings/haskell/Setup.hs index 65a8ca896a4e..1949196ae6b8 100644 --- a/bindings/haskell/Setup.hs +++ b/bindings/haskell/Setup.hs @@ -51,7 +51,8 @@ rustConfHook (description, buildInfo) flags = do library { PD.libBuildInfo = libraryBuildInfo - { PD.extraLibDirs = dir : PD.extraLibDirs libraryBuildInfo + { PD.extraLibDirs = dir : PD.extraLibDirs libraryBuildInfo, + PD.ldOptions = ("-Wl,-rpath," ++ dir) : (PD.ldOptions libraryBuildInfo) } } } @@ -60,27 +61,18 @@ rustConfHook (description, buildInfo) flags = do rustBuildHook :: PD.PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO () rustBuildHook pkg_descr lbi hooks flags = do putStrLn "Building Rust code..." + let isRelease = withProfLib lbi let cargoArgs = if isRelease then ["build", "--release"] else ["build"] rawSystemExit (fromFlag $ buildVerbosity flags) "cargo" cargoArgs - createHSLink putStrLn "Build Rust code success!" buildHook simpleUserHooks pkg_descr lbi hooks flags - where - createHSLink = do - dir <- getLibDir isRelease - ghcVersion <- init <$> readProcess "ghc" ["--numeric-version"] "" - let srcPath = dir ++ "/libopendal_hs." ++ getDynamicLibExtension lbi - let destPath = dir ++ "/libopendal_hs-ghc" ++ ghcVersion ++ "." ++ getDynamicLibExtension lbi - exist <- doesFileExist destPath - when (not exist) $ createFileLink srcPath destPath - isRelease = withProfLib lbi getLibDir :: Bool -> IO String getLibDir isRelease = do cargoPath <- readProcess "cargo" ["locate-project", "--workspace", "--message-format=plain"] "" let dir = take (length cargoPath - 11) cargoPath --