tiny_tds 3.2.0-x86_64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +20 -0
  3. data/.gitattributes +1 -0
  4. data/.github/workflows/ci.yml +590 -0
  5. data/.gitignore +22 -0
  6. data/.rubocop.yml +31 -0
  7. data/CHANGELOG.md +305 -0
  8. data/CODE_OF_CONDUCT.md +31 -0
  9. data/Gemfile +2 -0
  10. data/ISSUE_TEMPLATE.md +38 -0
  11. data/MIT-LICENSE +23 -0
  12. data/README.md +493 -0
  13. data/Rakefile +67 -0
  14. data/VERSION +1 -0
  15. data/bin/defncopy-ttds +3 -0
  16. data/bin/tsql-ttds +3 -0
  17. data/docker-compose.yml +34 -0
  18. data/exe/.keep +0 -0
  19. data/ext/tiny_tds/client.c +492 -0
  20. data/ext/tiny_tds/client.h +53 -0
  21. data/ext/tiny_tds/extconf.rb +190 -0
  22. data/ext/tiny_tds/extconsts.rb +8 -0
  23. data/ext/tiny_tds/result.c +626 -0
  24. data/ext/tiny_tds/result.h +32 -0
  25. data/ext/tiny_tds/tiny_tds_ext.c +15 -0
  26. data/ext/tiny_tds/tiny_tds_ext.h +17 -0
  27. data/lib/tiny_tds/2.7/tiny_tds.so +0 -0
  28. data/lib/tiny_tds/3.0/tiny_tds.so +0 -0
  29. data/lib/tiny_tds/3.1/tiny_tds.so +0 -0
  30. data/lib/tiny_tds/3.2/tiny_tds.so +0 -0
  31. data/lib/tiny_tds/3.3/tiny_tds.so +0 -0
  32. data/lib/tiny_tds/3.4/tiny_tds.so +0 -0
  33. data/lib/tiny_tds/bin.rb +90 -0
  34. data/lib/tiny_tds/client.rb +132 -0
  35. data/lib/tiny_tds/error.rb +12 -0
  36. data/lib/tiny_tds/gem.rb +23 -0
  37. data/lib/tiny_tds/result.rb +5 -0
  38. data/lib/tiny_tds/version.rb +3 -0
  39. data/lib/tiny_tds.rb +42 -0
  40. data/patches/freetds/1.00.27/0001-mingw_missing_inet_pton.diff +34 -0
  41. data/patches/freetds/1.00.27/0002-Don-t-use-MSYS2-file-libws2_32.diff +28 -0
  42. data/patches/libiconv/1.14/1-avoid-gets-error.patch +17 -0
  43. data/ports/x86_64-linux-musl/bin/defncopy +0 -0
  44. data/ports/x86_64-linux-musl/bin/tsql +0 -0
  45. data/ports/x86_64-linux-musl/lib/libsybdb.so.5 +0 -0
  46. data/setup_cimgruby_dev.sh +25 -0
  47. data/start_dev.sh +21 -0
  48. data/tasks/native_gem.rake +16 -0
  49. data/tasks/package.rake +6 -0
  50. data/tasks/ports.rake +24 -0
  51. data/tasks/test.rake +7 -0
  52. data/test/bin/install-freetds.sh +18 -0
  53. data/test/bin/install-mssql.ps1 +42 -0
  54. data/test/bin/install-mssqltools.sh +9 -0
  55. data/test/bin/install-openssl.sh +18 -0
  56. data/test/bin/restore-from-native-gem.ps1 +10 -0
  57. data/test/bin/setup_tinytds_db.sh +7 -0
  58. data/test/bin/setup_volume_permissions.sh +10 -0
  59. data/test/client_test.rb +266 -0
  60. data/test/gem_test.rb +100 -0
  61. data/test/result_test.rb +708 -0
  62. data/test/schema/1px.gif +0 -0
  63. data/test/schema/sqlserver_2017.sql +140 -0
  64. data/test/schema/sqlserver_azure.sql +140 -0
  65. data/test/schema_test.rb +417 -0
  66. data/test/sql/db-create.sql +18 -0
  67. data/test/sql/db-login.sql +38 -0
  68. data/test/test_helper.rb +244 -0
  69. data/test/thread_test.rb +89 -0
  70. data/tiny_tds.gemspec +31 -0
  71. metadata +259 -0
@@ -0,0 +1,190 @@
1
+ require "mkmf"
2
+ require_relative "extconsts"
3
+
4
+ if ENV["MAINTAINER_MODE"]
5
+ warn "Maintainer mode enabled."
6
+ $CFLAGS << # standard:disable Style/GlobalVars
7
+ " -Wall" \
8
+ " -ggdb" \
9
+ " -DDEBUG" \
10
+ " -pedantic"
11
+ $LDFLAGS << # standard:disable Style/GlobalVars
12
+ " -ggdb"
13
+ end
14
+
15
+ if (gem_platform = with_config("cross-build"))
16
+ require "mini_portile2"
17
+
18
+ openssl_platform = with_config("openssl-platform")
19
+
20
+ class BuildRecipe < MiniPortile
21
+ attr_accessor :gem_platform
22
+
23
+ def initialize(name, version, files)
24
+ super(name, version)
25
+ self.files = files
26
+ rootdir = File.expand_path("../../..", __FILE__)
27
+ self.target = File.join(rootdir, "ports")
28
+ self.patch_files = Dir[File.join("patches", self.name, self.version, "*.patch")].sort
29
+ end
30
+
31
+ # this will yield all ports into the same directory, making our path configuration for the linker easier
32
+ def port_path
33
+ "#{@target}/#{gem_platform}"
34
+ end
35
+
36
+ def cook_and_activate
37
+ checkpoint = File.join(target, "#{name}-#{version}-#{gem_platform}.installed")
38
+
39
+ unless File.exist?(checkpoint)
40
+ cook
41
+ FileUtils.touch checkpoint
42
+ end
43
+
44
+ activate
45
+ self
46
+ end
47
+ end
48
+
49
+ openssl_recipe = BuildRecipe.new("openssl", OPENSSL_VERSION, [OPENSSL_SOURCE_URI]).tap do |recipe|
50
+ class << recipe
51
+ attr_accessor :openssl_platform
52
+
53
+ def configure
54
+ envs = []
55
+ envs << "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS" if MiniPortile.windows?
56
+ envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if MiniPortile.linux?
57
+ execute("configure", ["env", *envs, "./Configure", openssl_platform, "threads", "-static", "CROSS_COMPILE=#{host}-", configure_prefix, "--libdir=lib"], altlog: "config.log")
58
+ end
59
+
60
+ def compile
61
+ execute("compile", "#{make_cmd} build_libs")
62
+ end
63
+
64
+ def install
65
+ execute("install", "#{make_cmd} install_dev")
66
+ end
67
+ end
68
+
69
+ recipe.gem_platform = gem_platform
70
+ recipe.openssl_platform = openssl_platform
71
+ recipe.cook_and_activate
72
+ end
73
+
74
+ libiconv_recipe = BuildRecipe.new("libiconv", ICONV_VERSION, [ICONV_SOURCE_URI]).tap do |recipe|
75
+ recipe.configure_options << "CFLAGS=-fPIC" if MiniPortile.linux?
76
+ recipe.gem_platform = gem_platform
77
+
78
+ recipe.cook_and_activate
79
+ end
80
+
81
+ # remove the ".la" files, otherwise libtool starts to complain when linking into FreeTDS
82
+ Dir.glob(File.join(libiconv_recipe.path, "lib", "**", "*.la")).each do |la_file|
83
+ File.delete(la_file)
84
+ end
85
+
86
+ freetds_recipe = BuildRecipe.new("freetds", FREETDS_VERSION, [FREETDS_SOURCE_URI]).tap do |recipe|
87
+ class << recipe
88
+ def configure_defaults
89
+ [
90
+ "--host=#{@host}",
91
+ "--enable-shared",
92
+ "--disable-static",
93
+ "--disable-odbc"
94
+ ]
95
+ end
96
+ end
97
+
98
+ # i am not 100% what is going on behind the scenes
99
+ # it seems that FreeTDS build system prefers OPENSSL_CFLAGS and OPENSSL_LIBS
100
+ # but the linker still relies on LIBS and CPPFLAGS
101
+ # removing one or the other leads to build failures in any case of FreeTDS
102
+ if MiniPortile.linux?
103
+ recipe.configure_options << "CFLAGS=-fPIC"
104
+ elsif MiniPortile.windows?
105
+ recipe.configure_options << "--enable-sspi"
106
+ end
107
+
108
+ # pass an additional runtime path to the linker so defncopy and tsql can find our shared sybdb
109
+ recipe.configure_options << "LDFLAGS=-L#{openssl_recipe.path}/lib #{"-Wl,-rpath='$$ORIGIN/../lib'" if MiniPortile.linux?}"
110
+ recipe.configure_options << "LIBS=-liconv -lssl -lcrypto #{"-lwsock32 -lgdi32 -lws2_32 -lcrypt32" if MiniPortile.windows?} #{"-ldl -lpthread" if MiniPortile.linux?}"
111
+ recipe.configure_options << "CPPFLAGS=-I#{openssl_recipe.path}/include"
112
+
113
+ recipe.configure_options << "OPENSSL_CFLAGS=-L#{openssl_recipe.path}/lib"
114
+ recipe.configure_options << "OPENSSL_LIBS=-lssl -lcrypto #{"-lwsock32 -lgdi32 -lws2_32 -lcrypt32" if MiniPortile.windows?} #{"-ldl -lpthread" if MiniPortile.linux?}"
115
+
116
+ recipe.configure_options << "--with-openssl=#{openssl_recipe.path}"
117
+ recipe.configure_options << "--with-libiconv-prefix=#{libiconv_recipe.path}"
118
+ recipe.configure_options << "--sysconfdir=C:/Sites" if MiniPortile.windows?
119
+
120
+ recipe.gem_platform = gem_platform
121
+ recipe.cook_and_activate
122
+ end
123
+
124
+ # enable relative path to later load the FreeTDS shared library
125
+ $LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../../ports/#{gem_platform}/lib'" # standard:disable Style/GlobalVars
126
+
127
+ dir_config("freetds", "#{freetds_recipe.path}/include", "#{freetds_recipe.path}/lib")
128
+ else
129
+ # Make sure to check the ports path for the configured host
130
+ architecture = RbConfig::CONFIG["arch"]
131
+
132
+ project_dir = File.expand_path("../../..", __FILE__)
133
+ freetds_ports_dir = File.join(project_dir, "ports", architecture, "freetds", FREETDS_VERSION)
134
+ freetds_ports_dir = File.expand_path(freetds_ports_dir)
135
+
136
+ # Add all the special path searching from the original tiny_tds build
137
+ # order is important here! First in, first searched.
138
+ DIRS = %w[
139
+ /opt/local
140
+ /usr/local
141
+ ]
142
+
143
+ if /darwin/i.match?(RbConfig::CONFIG["host_os"])
144
+ # Ruby below 2.7 seems to label the host CPU on Apple Silicon as aarch64
145
+ # 2.7 and above print is as ARM64
146
+ target_host_cpu = (Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")) ? "aarch64" : "arm64"
147
+
148
+ if RbConfig::CONFIG["host_cpu"] == target_host_cpu
149
+ # Homebrew on Apple Silicon installs into /opt/hombrew
150
+ # https://docs.brew.sh/Installation
151
+ # On Intel Macs, it is /usr/local, so no changes necessary to DIRS
152
+ DIRS.unshift("/opt/homebrew")
153
+ end
154
+ end
155
+
156
+ if ENV["RI_DEVKIT"] && ENV["MINGW_PREFIX"] # RubyInstaller Support
157
+ DIRS.unshift(File.join(ENV["RI_DEVKIT"], ENV["MINGW_PREFIX"]))
158
+ end
159
+
160
+ # Add the ports directory if it exists for local developer builds
161
+ DIRS.unshift(freetds_ports_dir) if File.directory?(freetds_ports_dir)
162
+
163
+ # Grab freetds environment variable for use by people on services like
164
+ # Heroku who they can't easily use bundler config to set directories
165
+ DIRS.unshift(ENV["FREETDS_DIR"]) if ENV.has_key?("FREETDS_DIR")
166
+
167
+ # Add the search paths for freetds configured above
168
+ ldirs = DIRS.flat_map do |path|
169
+ ldir = "#{path}/lib"
170
+ [ldir, "#{ldir}/freetds"]
171
+ end
172
+
173
+ idirs = DIRS.flat_map do |path|
174
+ idir = "#{path}/include"
175
+ [idir, "#{idir}/freetds"]
176
+ end
177
+
178
+ puts "looking for freetds headers in the following directories:\n#{idirs.map { |a| " - #{a}\n" }.join}"
179
+ puts "looking for freetds library in the following directories:\n#{ldirs.map { |a| " - #{a}\n" }.join}"
180
+ dir_config("freetds", idirs, ldirs)
181
+ end
182
+
183
+ find_header("sybfront.h") or abort "Can't find the 'sybfront.h' header"
184
+ find_header("sybdb.h") or abort "Can't find the 'sybdb.h' header"
185
+
186
+ unless have_library("sybdb", "dbanydatecrack")
187
+ abort "Failed! Do you have FreeTDS 1.0.0 or higher installed?"
188
+ end
189
+
190
+ create_makefile("tiny_tds/tiny_tds")
@@ -0,0 +1,8 @@
1
+ ICONV_VERSION = ENV["TINYTDS_ICONV_VERSION"] || "1.18"
2
+ ICONV_SOURCE_URI = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"
3
+
4
+ OPENSSL_VERSION = ENV["TINYTDS_OPENSSL_VERSION"] || "3.4.0"
5
+ OPENSSL_SOURCE_URI = "https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
6
+
7
+ FREETDS_VERSION = ENV["TINYTDS_FREETDS_VERSION"] || "1.4.26"
8
+ FREETDS_SOURCE_URI = "http://www.freetds.org/files/stable/freetds-#{FREETDS_VERSION}.tar.bz2"