@@ -23,7 +23,7 @@ defmodule Tailwind do
23
23
24
24
## Tailwind configuration
25
25
26
- There are two global configurations for the tailwind application:
26
+ There are four global configurations for the tailwind application:
27
27
28
28
* `:version` - the expected tailwind version
29
29
@@ -35,6 +35,10 @@ defmodule Tailwind do
35
35
default, it is automatically downloaded and placed inside
36
36
the `_build` directory of your current app
37
37
38
+ * `:target` - the target architecture for the tailwind executable.
39
+ For example `"linux-x64-musl"`. By default, it is automatically detected
40
+ based on system information.
41
+
38
42
Overriding the `:path` is not recommended, as we will automatically
39
43
download and manage `tailwind` for you. But in case you can't download
40
44
it (for example, GitHub behind a proxy), you may want to
@@ -108,6 +112,13 @@ defmodule Tailwind do
108
112
Application . get_env ( :tailwind , :version , latest_version ( ) )
109
113
end
110
114
115
+ @ doc """
116
+ Returns the configured tailwind target. By default, it is automatically detected.
117
+ """
118
+ def configured_target do
119
+ Application . get_env ( :tailwind , :target , target ( ) )
120
+ end
121
+
111
122
@ doc """
112
123
Returns the configuration for the given profile.
113
124
@@ -136,7 +147,7 @@ defmodule Tailwind do
136
147
The executable may not be available if it was not yet installed.
137
148
"""
138
149
def bin_path do
139
- name = "tailwind-#{ target ( ) } "
150
+ name = "tailwind-#{ configured_target ( ) } "
140
151
141
152
Application . get_env ( :tailwind , :path ) ||
142
153
if Code . ensure_loaded? ( Mix.Project ) do
@@ -246,19 +257,45 @@ defmodule Tailwind do
246
257
# tailwindcss-windows-x64.exe
247
258
defp target do
248
259
arch_str = :erlang . system_info ( :system_architecture )
249
- [ arch | _ ] = arch_str |> List . to_string ( ) |> String . split ( "-" )
250
-
251
- case { :os . type ( ) , arch , :erlang . system_info ( :wordsize ) * 8 } do
252
- { { :win32 , _ } , _arch , 64 } -> "windows-x64.exe"
253
- { { :unix , :darwin } , arch , 64 } when arch in ~w( arm aarch64) -> "macos-arm64"
254
- { { :unix , :darwin } , "x86_64" , 64 } -> "macos-x64"
255
- { { :unix , :freebsd } , "aarch64" , 64 } -> "freebsd-arm64"
256
- { { :unix , :freebsd } , arch , 64 } when arch in ~w( x86_64 amd64) -> "freebsd-x64"
257
- { { :unix , :linux } , "aarch64" , 64 } -> "linux-arm64"
258
- { { :unix , :linux } , "arm" , 32 } -> "linux-armv7"
259
- { { :unix , :linux } , "armv7" <> _ , 32 } -> "linux-armv7"
260
- { { :unix , _osname } , arch , 64 } when arch in ~w( x86_64 amd64) -> "linux-x64"
261
- { _os , _arch , _wordsize } -> raise "tailwind is not available for architecture: #{ arch_str } "
260
+ target_triple = arch_str |> List . to_string ( ) |> String . split ( "-" )
261
+
262
+ { arch , abi } =
263
+ case target_triple do
264
+ [ arch , _vendor , _system , abi ] -> { arch , abi }
265
+ [ arch , _vendor , abi ] -> { arch , abi }
266
+ [ arch | _ ] -> { arch , nil }
267
+ end
268
+
269
+ case { :os . type ( ) , arch , abi , :erlang . system_info ( :wordsize ) * 8 } do
270
+ { { :win32 , _ } , _arch , _abi , 64 } ->
271
+ "windows-x64.exe"
272
+
273
+ { { :unix , :darwin } , arch , _abi , 64 } when arch in ~w( arm aarch64) ->
274
+ "macos-arm64"
275
+
276
+ { { :unix , :darwin } , "x86_64" , _abi , 64 } ->
277
+ "macos-x64"
278
+
279
+ { { :unix , :freebsd } , "aarch64" , _abi , 64 } ->
280
+ "freebsd-arm64"
281
+
282
+ { { :unix , :freebsd } , arch , _abi , 64 } when arch in ~w( x86_64 amd64) ->
283
+ "freebsd-x64"
284
+
285
+ { { :unix , :linux } , "aarch64" , "musl" , 64 } ->
286
+ "linux-arm64-musl"
287
+
288
+ { { :unix , :linux } , "aarch64" , _abi , 64 } ->
289
+ "linux-arm64"
290
+
291
+ { { :unix , _osname } , arch , "musl" , 64 } when arch in ~w( x86_64 amd64) ->
292
+ "linux-x64-musl"
293
+
294
+ { { :unix , _osname } , arch , _abi , 64 } when arch in ~w( x86_64 amd64) ->
295
+ "linux-x64"
296
+
297
+ { _os , _arch , _abi , _wordsize } ->
298
+ raise "tailwind is not available for architecture: #{ arch_str } "
262
299
end
263
300
end
264
301
@@ -297,6 +334,18 @@ defmodule Tailwind do
297
334
{ _ , { :ok , { { _ , 200 , _ } , _headers , body } } } ->
298
335
body
299
336
337
+ { _ , { :ok , { { _ , 404 , _ } , _headers , _body } } } ->
338
+ raise """
339
+ The tailwind binary couldn't be found at: #{ url }
340
+
341
+ This could mean that you're trying to install a version that does not support the detected
342
+ target architecture.
343
+
344
+ You can see the available files for the configured version at:
345
+
346
+ https://github.com/tailwindlabs/tailwindcss/releases/tag/v#{ configured_version ( ) }
347
+ """
348
+
300
349
{ true , { :error , { :failed_connect , [ { :to_address , _ } , { inet , _ , reason } ] } } }
301
350
when inet in [ :inet , :inet6 ] and
302
351
reason in [ :ehostunreach , :enetunreach , :eprotonosupport , :nxdomain ] ->
@@ -314,7 +363,7 @@ defmodule Tailwind do
314
363
your certificates are set via OTP ca certfile overide via SSL configuration.
315
364
316
365
2. Manually download the executable from the URL above and
317
- place it inside "_build/tailwind-#{ target ( ) } "
366
+ place it inside "_build/tailwind-#{ configured_target ( ) } "
318
367
319
368
3. Install and use Tailwind from npmJS. See our module documentation
320
369
to learn more: https://hexdocs.pm/tailwind
@@ -361,6 +410,6 @@ defmodule Tailwind do
361
410
defp get_url ( base_url ) do
362
411
base_url
363
412
|> String . replace ( "$version" , configured_version ( ) )
364
- |> String . replace ( "$target" , target ( ) )
413
+ |> String . replace ( "$target" , configured_target ( ) )
365
414
end
366
415
end
0 commit comments