|
| 1 | +class SqlbSqlcipher < Formula |
| 2 | + desc "SQLite extension providing 256-bit AES encryption" |
| 3 | + homepage "https://www.zetetic.net/sqlcipher/" |
| 4 | + url "https://github.com/sqlcipher/sqlcipher/archive/refs/tags/v4.6.1.tar.gz" |
| 5 | + # version "4.6.1" |
| 6 | + sha256 "d8f9afcbc2f4b55e316ca4ada4425daf3d0b4aab25f45e11a802ae422b9f53a3" |
| 7 | + license "BSD-3-Clause" |
| 8 | + head "https://github.com/sqlcipher/sqlcipher.git", branch: "master" |
| 9 | + |
| 10 | + livecheck do |
| 11 | + url :stable |
| 12 | + strategy :github_latest |
| 13 | + end |
| 14 | + |
| 15 | + bottle do |
| 16 | + root_url "https://github.com/lucydodo/homebrew-tap/releases/download/sqlb-sqlcipher-4.6.1" |
| 17 | + sha256 cellar: :any, arm64_sonoma: "1c3b07faf269425e957a21ce0835e00339a4442d9533e89f7e0781e449804da8" |
| 18 | + end |
| 19 | + |
| 20 | + depends_on arch: :arm64 |
| 21 | + depends_on "sqlb-openssl@3" |
| 22 | + |
| 23 | + # Build scripts require tclsh. `--disable-tcl` only skips building extension |
| 24 | + uses_from_macos "tcl-tk" => :build |
| 25 | + uses_from_macos "sqlite" |
| 26 | + uses_from_macos "zlib" |
| 27 | + |
| 28 | + def install |
| 29 | + # Determine the minimum macOS version. |
| 30 | + # Match the required version of the DB Browser for SQLite app. |
| 31 | + ENV["MACOSX_DEPLOYMENT_TARGET"] = "10.13" |
| 32 | + ENV.append "CPPFLAGS", "-mmacosx-version-min=10.13" |
| 33 | + ENV.append "LDFLAGS", "-mmacosx-version-min=10.13" |
| 34 | + |
| 35 | + ENV.append "CFLAGS", "-arch x86_64" |
| 36 | + |
| 37 | + args = %W[ |
| 38 | + --prefix=#{prefix}/darwin64-x86_64-cc |
| 39 | + --enable-tempstore=yes |
| 40 | + --with-crypto-lib=#{Formula["sqlb-openssl@3"].opt_prefix} |
| 41 | + --enable-load-extension |
| 42 | + --disable-tcl |
| 43 | + ] |
| 44 | + |
| 45 | + # Build with full-text search enabled |
| 46 | + cflags = %w[ |
| 47 | + -DSQLCIPHER_CRYPTO_OPENSSL |
| 48 | + -DSQLITE_ENABLE_COLUMN_METADATA |
| 49 | + -DSQLITE_ENABLE_FTS3 |
| 50 | + -DSQLITE_ENABLE_FTS3_PARENTHESIS |
| 51 | + -DSQLITE_ENABLE_FTS5 |
| 52 | + -DSQLITE_ENABLE_GEOPOLY |
| 53 | + -DSQLITE_ENABLE_JSON1 |
| 54 | + -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 |
| 55 | + -DSQLITE_ENABLE_RTREE |
| 56 | + -DSQLITE_ENABLE_SNAPSHOT=1 |
| 57 | + -DSQLITE_ENABLE_STAT4 |
| 58 | + -DSQLITE_HAS_CODEC |
| 59 | + -DSQLITE_SOUNDEX |
| 60 | + ].join(" ") |
| 61 | + args << "CFLAGS=#{cflags}" |
| 62 | + |
| 63 | + system "./configure", *args |
| 64 | + system "arch", "-x86_64", "make" |
| 65 | + system "make", "install" |
| 66 | + |
| 67 | + ENV.delete("CFLAGS") |
| 68 | + |
| 69 | + args = %W[ |
| 70 | + --prefix=#{prefix} |
| 71 | + --enable-tempstore=yes |
| 72 | + --with-crypto-lib=#{Formula["sqlb-openssl@3"].opt_prefix} |
| 73 | + --enable-load-extension |
| 74 | + --disable-tcl |
| 75 | + ] |
| 76 | + |
| 77 | + # Build with full-text search enabled |
| 78 | + cflags = %w[ |
| 79 | + -DSQLCIPHER_CRYPTO_OPENSSL |
| 80 | + -DSQLITE_ENABLE_COLUMN_METADATA |
| 81 | + -DSQLITE_ENABLE_FTS3 |
| 82 | + -DSQLITE_ENABLE_FTS3_PARENTHESIS |
| 83 | + -DSQLITE_ENABLE_FTS5 |
| 84 | + -DSQLITE_ENABLE_GEOPOLY |
| 85 | + -DSQLITE_ENABLE_JSON1 |
| 86 | + -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 |
| 87 | + -DSQLITE_ENABLE_RTREE |
| 88 | + -DSQLITE_ENABLE_SNAPSHOT=1 |
| 89 | + -DSQLITE_ENABLE_STAT4 |
| 90 | + -DSQLITE_HAS_CODEC |
| 91 | + -DSQLITE_SOUNDEX |
| 92 | + ].join(" ") |
| 93 | + args << "CFLAGS=#{cflags}" |
| 94 | + |
| 95 | + system "make", "clean" |
| 96 | + system "./configure", *args |
| 97 | + system "make" |
| 98 | + system "make", "install" |
| 99 | + |
| 100 | + mv "#{lib}/libsqlcipher.0.dylib", "#{lib}/libsqlcipher.0-arm64.dylib" |
| 101 | + dylib_arm64 = MachO::MachOFile.new("#{lib}/libsqlcipher.0-arm64.dylib") |
| 102 | + dylib_x86_64 = MachO::MachOFile.new("#{prefix}/darwin64-x86_64-cc/lib/libsqlcipher.0.dylib") |
| 103 | + fat = MachO::FatFile.new_from_machos(dylib_arm64, dylib_x86_64) |
| 104 | + fat.write("#{lib}/libsqlcipher.0.dylib") |
| 105 | + |
| 106 | + rm "#{lib}/libsqlcipher.dylib" |
| 107 | + rm_r "#{prefix}/darwin64-x86_64-cc" |
| 108 | + ln_s "#{lib}/libsqlcipher.0.dylib", "#{lib}/libsqlcipher.dylib" |
| 109 | + end |
| 110 | + |
| 111 | + test do |
| 112 | + path = testpath/"school.sql" |
| 113 | + path.write <<~EOS |
| 114 | + create table students (name text, age integer); |
| 115 | + insert into students (name, age) values ('Bob', 14); |
| 116 | + insert into students (name, age) values ('Sue', 12); |
| 117 | + insert into students (name, age) values ('Tim', json_extract('{"age": 13}', '$.age')); |
| 118 | + select name from students order by age asc; |
| 119 | + EOS |
| 120 | + |
| 121 | + names = shell_output("#{bin}/sqlcipher < #{path}").strip.split("\n") |
| 122 | + assert_equal %w[Sue Tim Bob], names |
| 123 | + end |
| 124 | +end |
0 commit comments