diff --git a/.github/workflows/bump.yaml b/.github/workflows/bump.yaml new file mode 100644 index 0000000..d417aad --- /dev/null +++ b/.github/workflows/bump.yaml @@ -0,0 +1,28 @@ +# https://github.com/nomeata/haskell-bounds-bump-action +on: + # allows manual triggering from https://github.com/../../actions/workflows/bump.yml + workflow_dispatch: + # runs weekly on Thursday at 8:00 + schedule: + # ┌───────────── minute (0 - 59) + # │ ┌───────────── hour (0 - 23) + # │ │ ┌───────────── day of the month (1 - 31) + # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) + # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) + # │ │ │ │ │ + # │ │ │ │ │ + # │ │ │ │ │ + # * * * * * + - cron: '0 0 * * 3' + +permissions: + contents: write + pull-requests: write + +jobs: + bump: + runs-on: ubuntu-latest + steps: + - uses: nomeata/haskell-bounds-bump-action@main + with: + test: false diff --git a/.github/workflows/cabal.yaml b/.github/workflows/cabal.yaml new file mode 100644 index 0000000..3bd40a2 --- /dev/null +++ b/.github/workflows/cabal.yaml @@ -0,0 +1,40 @@ +on: + pull_request: + push: + branches: + - master +jobs: + build: + + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + ghc: # should mirror current stable releases: https://www.haskell.org/ghc/download.html + - '9.8' + - '9.10' + os: [ubuntu-latest, macOS-latest, windows-latest] + cabal: ['latest'] + + steps: + - uses: actions/checkout@v3 + - uses: haskell/actions/setup@v2 # https://github.com/haskell/actions/tree/main/setup#haskellactionssetup + with: + ghc-version: ${{ matrix.ghc }} + + - name: Cabal cache + uses: actions/cache@v3 + env: + cache-name: cache-cabal + with: + path: ~/.cabal + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + - name: Cabal update + run: cabal update + - name: Build using cabal + run: cabal build all + - name: Test + run: cabal test all diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml new file mode 100644 index 0000000..ba6acc1 --- /dev/null +++ b/.github/workflows/nix.yaml @@ -0,0 +1,31 @@ +on: + pull_request: + push: + branches: + - master +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Local cache + uses: actions/cache@v5 + with: + path: /nix/store + key: "${{ runner.os }}-nix-cache" + - uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + + # follow guide: https://nix.dev/tutorials/continuous-integration-github-actions + # this uses the tokens which are revokable + - uses: cachix/cachix-action@v15 + with: + name: jappie + # If you chose API tokens for write access OR if you have a private cache + # authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' + - run: nix-build + - run: nix-shell --run "echo OK" diff --git a/README.md b/README.md index e128d8a..a560eed 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,15 @@ memory [![BSD](http://b.repl.ca/v1/license-BSD-blue.png)](http://en.wikipedia.org/wiki/BSD_licenses) [![Haskell](http://b.repl.ca/v1/language-haskell-lightgrey.png)](http://haskell.org) +This is a fork of memory. It's open to accept changes from anyone, +and aims to use existing well maintained libraries as much as possible. +The fork is necessary because the original maintainer decided to +exit Haskell. + +Note that this is /not/ a redesign of memory. +It's just here to provide stability so +that others can create better alternatives. + Documentation: [ram on hackage](http://hackage.haskell.org/package/ram) A generic memory and related abstraction for haskell: @@ -18,22 +27,3 @@ Also provides some useful helpers: * Fast Hashing : [SipHash](https://131002.net/siphash/), [FNV1](http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function). * Built-in base encoding : Base16, Base32, [Base64](http://en.wikipedia.org/wiki/Base64). -Versioning ----------- - -Development versions are an incremental number prefixed by 0. -No specific meaning is associated with the versions, specially -no API stability. - -Production versions : TBD - -Coding Style ------------- - -The coding style of this project mostly follows: -[haskell-style](https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md) - -Support -------- - -See [Haskell packages guidelines](https://github.com/vincenthz/haskell-pkg-guidelines/blob/master/README.md#support) diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..da2baed --- /dev/null +++ b/default.nix @@ -0,0 +1,4 @@ +{ hpkgs ? import ./nix/hpkgs.nix {} +, +}: +hpkgs.ram diff --git a/nix/hpkgs.nix b/nix/hpkgs.nix new file mode 100644 index 0000000..c30fce2 --- /dev/null +++ b/nix/hpkgs.nix @@ -0,0 +1,13 @@ +{ pkgs ? import ./pkgs.nix { } +, +}: +# you can pin a specific ghc version with +# pkgs.haskell.packages.ghc984 for example. +# this allows you to create multiple compiler targets via nix. +pkgs.haskellPackages.override { + overrides = hnew: hold: { + # NB this is a bit silly because nix files are now considered for the build + # bigger projects should consider putting haskell stuff in a subfolder + ram = hnew.callCabal2nix "ram" ../. { }; + }; +} diff --git a/nix/pkgs.nix b/nix/pkgs.nix new file mode 100644 index 0000000..1766122 --- /dev/null +++ b/nix/pkgs.nix @@ -0,0 +1,4 @@ +{ sources ? import ../npins +, +}: +import sources.nixpkgs { } diff --git a/npins/default.nix b/npins/default.nix new file mode 100644 index 0000000..6592476 --- /dev/null +++ b/npins/default.nix @@ -0,0 +1,146 @@ +/* + This file is provided under the MIT licence: + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +# Generated by npins. Do not modify; will be overwritten regularly +let + data = builtins.fromJSON (builtins.readFile ./sources.json); + version = data.version; + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = + first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # If the environment variable NPINS_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + # (Taken from Niv for compatibility) + mayOverride = + name: path: + let + envVarName = "NPINS_OVERRIDE_${saneName}"; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv envVarName; + in + if ersatz == "" then + path + else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( + if builtins.substring 0 1 ersatz == "/" then + /. + ersatz + else + /. + builtins.getEnv "PWD" + "/${ersatz}" + ); + + mkSource = + name: spec: + assert spec ? type; + let + path = + if spec.type == "Git" then + mkGitSource spec + else if spec.type == "GitRelease" then + mkGitSource spec + else if spec.type == "PyPi" then + mkPyPiSource spec + else if spec.type == "Channel" then + mkChannelSource spec + else if spec.type == "Tarball" then + mkTarballSource spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = mayOverride name path; }; + + mkGitSource = + { + repository, + revision, + url ? null, + submodules, + hash, + branch ? null, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null && !submodules then + builtins.fetchTarball { + inherit url; + sha256 = hash; # FIXME: check nix version & use SRI hashes + } + else + let + url = + if repository.type == "Git" then + repository.url + else if repository.type == "GitHub" then + "https://github.com/${repository.owner}/${repository.repo}.git" + else if repository.type == "GitLab" then + "${repository.server}/${repository.repo_path}.git" + else + throw "Unrecognized repository type ${repository.type}"; + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName url revision; + in + builtins.fetchGit { + rev = revision; + inherit name; + # hash = hash; + inherit url submodules; + }; + + mkPyPiSource = + { url, hash, ... }: + builtins.fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { url, hash, ... }: + builtins.fetchTarball { + inherit url; + sha256 = hash; + }; + + mkTarballSource = + { + url, + locked_url ? url, + hash, + ... + }: + builtins.fetchTarball { + url = locked_url; + sha256 = hash; + }; +in +if version == 5 then + builtins.mapAttrs mkSource data.pins +else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" diff --git a/npins/sources.json b/npins/sources.json new file mode 100644 index 0000000..7ed749b --- /dev/null +++ b/npins/sources.json @@ -0,0 +1,11 @@ +{ + "pins": { + "nixpkgs": { + "type": "Channel", + "name": "nixpkgs-unstable", + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.11pre891648.f6b44b240152/nixexprs.tar.xz", + "hash": "0rljaahlkcrcjqd9sj5iyv9zng4yqns1215kanm7hi4w9gri0b74" + } + }, + "version": 5 +} diff --git a/ram.cabal b/ram.cabal index f7c4fd3..4924155 100644 --- a/ram.cabal +++ b/ram.cabal @@ -27,23 +27,13 @@ Maintainer: hi@jappie.me Category: memory Stability: experimental Build-Type: Simple -Homepage: https://github.com/vincenthz/hs-memory -Bug-Reports: https://github.com/vincenthz/hs-memory/issues +Homepage: https://github.com/jappeace/ram +Bug-Reports: https://github.com/jappeace/ram/issues extra-doc-files: README.md CHANGELOG.md source-repository head type: git - location: https://github.com/vincenthz/hs-memory - -Flag support_bytestring - Description: add non-orphan bytearray support for bytestring - Default: True - Manual: True - -Flag support_deepseq - Description: add deepseq instances for memory types - Default: True - Manual: True + location: https://github.com/jappeace/ram Library Exposed-modules: Data.ByteArray @@ -73,11 +63,10 @@ Library Data.ByteArray.MemView Data.ByteArray.View Exposed-modules: Data.ByteArray.Sized - if impl(ghc < 8.8) - buildable: False - else - build-depends: base - , ghc-prim + build-depends: base < 4.23 + , ghc-prim < 0.14 + , bytestring < 0.13 + , deepseq >= 1.1 && < 1.17 -- FIXME armel or mispel is also little endian. -- might be a good idea to also add a runtime autodetect mode. -- ARCH_ENDIAN_UNKNOWN @@ -88,14 +77,6 @@ Library else Other-modules: Data.Memory.MemMap.Posix - -- optional support bytearray instance for bytestring - if flag(support_bytestring) - CPP-options: -DWITH_BYTESTRING_SUPPORT - Build-depends: bytestring - if flag(support_deepseq) - CPP-options: -DWITH_DEEPSEQ_SUPPORT - Build-depends: deepseq >= 1.1 - ghc-options: -Wall -fwarn-tabs default-language: Haskell2010 diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..dfe87e7 --- /dev/null +++ b/shell.nix @@ -0,0 +1,14 @@ +{ + hpkgs ? import ./nix/hpkgs.nix {}, + pkgs ? import ./nix/pkgs.nix {}, +}: +hpkgs.shellFor { + packages = ps: [ ps."ram" ]; + withHoogle = false; + + buildInputs = [ + hpkgs.haskell-language-server + pkgs.ghcid + pkgs.cabal-install + ]; +}