@@ -9,6 +9,11 @@ task install: %w[cli.rb] do
99end
1010
1111CLEAN . include %w[
12+ true-aarch64
13+ true-arm
14+ true-i386
15+ true-riscv64
16+ true-x86_64
1217 protoc.exe
1318 ruby
1419 *.proto
6570
6671task 'dart-sass' do
6772 Rake ::Task [ 'dart-sass/sass' ] . invoke
73+
74+ if SassConfig . linuxulator?
75+ begin
76+ sh 'dart-sass/sass' , '--version'
77+ rescue StandardError
78+ rm_rf 'dart-sass'
79+ raise NotImplementedError
80+ end
81+ end
6882rescue NotImplementedError
6983 Rake ::Task [ 'node_modules/sass' ] . invoke
7084end
@@ -158,6 +172,123 @@ rule '_pb.rb' => %w[.proto protoc.exe] do |t|
158172 sh './protoc.exe' , '--proto_path=.' , '--ruby_out=.' , t . source
159173end
160174
175+ rule ( /^true-\w +$/ ) do |t |
176+ require_relative '../../lib/sass/elf'
177+
178+ elf = Sass . const_get ( :ELF )
179+
180+ case t . name . delete_prefix ( 'true-' )
181+ when 'aarch64'
182+ ei_class = elf ::ELFCLASS64
183+ ei_data = elf ::ELFDATA2LSB
184+ e_machine = 0xb7
185+ e_flags = 0
186+
187+ # 0x0000000000000078: A8 0B 80 D2 mov x8, #0x5d
188+ # 0x000000000000007c: 00 00 80 D2 mov x0, #0
189+ # 0x0000000000000080: 01 00 00 D4 svc #0
190+ entry = [ 'a80b80d2000080d2010000d4' ] . pack ( 'H*' )
191+ when 'arm'
192+ ei_class = elf ::ELFCLASS32
193+ ei_data = elf ::ELFDATA2LSB
194+ e_machine = 0x28
195+ e_flags = 0x5000400
196+
197+ # 0x0000000000000054: 00 00 A0 E3 mov r0, #0
198+ # 0x0000000000000058: 01 70 A0 E3 mov r7, #1
199+ # 0x000000000000005c: 00 00 00 EF svc #0
200+ entry = [ '0000a0e30170a0e3000000ef' ] . pack ( 'H*' )
201+ when 'riscv64'
202+ ei_class = elf ::ELFCLASS64
203+ ei_data = elf ::ELFDATA2LSB
204+ e_machine = 0xf3
205+ e_flags = 0x5
206+
207+ # 0x0000000000000078: 93 08 D0 05 addi a7, x0, 93
208+ # 0x000000000000007c: 01 45 c.li a0, 0
209+ # 0x000000000000007e: 73 00 00 00 ecall
210+ entry = [ '9308d005014573000000' ] . pack ( 'H*' )
211+ when 'x86_64'
212+ ei_class = elf ::ELFCLASS64
213+ ei_data = elf ::ELFDATA2LSB
214+ e_machine = 0x3e
215+ e_flags = 0
216+
217+ # 0x0000000000000078: 31 FF xor edi, edi
218+ # 0x000000000000007a: B8 3C 00 00 00 mov eax, 0x3c
219+ # 0x000000000000007f: 0F 05 syscall
220+ entry = [ '31ffb83c0000000f05' ] . pack ( 'H*' )
221+ when 'i386'
222+ ei_class = elf ::ELFCLASS32
223+ ei_data = elf ::ELFDATA2LSB
224+ e_machine = 0x03
225+ e_flags = 0
226+
227+ # 0x0000000000000054: 31 DB xor ebx, ebx
228+ # 0x0000000000000056: B8 01 00 00 00 mov eax, 1
229+ # 0x000000000000005b: CD 80 int 0x80
230+ entry = [ '31dbb801000000cd80' ] . pack ( 'H*' )
231+ else
232+ raise NotImplementedError
233+ end
234+
235+ File . open ( t . name , 'wb' , 0o755 ) do |file |
236+ elf . allocate . instance_eval do
237+ case ei_class
238+ when elf ::ELFCLASS32
239+ e_ehsize = elf ::Elf32_Ehdr . sizeof
240+ e_phentsize = elf ::Elf32_Phdr . sizeof
241+ e_shentsize = elf ::Elf32_Shdr . sizeof
242+ when elf ::ELFCLASS64
243+ e_ehsize = elf ::Elf64_Ehdr . sizeof
244+ e_phentsize = elf ::Elf64_Phdr . sizeof
245+ e_shentsize = elf ::Elf64_Shdr . sizeof
246+ else
247+ raise EncodingError
248+ end
249+ e_phoff = e_ehsize
250+ p_offset = e_phoff + e_phentsize
251+ e_entry = ( 2 **22 ) + p_offset
252+ p_vaddr = e_entry
253+ p_filesz = entry . length
254+ p_memsz = p_filesz
255+
256+ @ehdr = {
257+ e_ident : [ 127 , 69 , 76 , 70 , ei_class , ei_data , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
258+ e_type : 2 ,
259+ e_machine :,
260+ e_version : 1 ,
261+ e_entry :,
262+ e_phoff :,
263+ e_shoff : 0 ,
264+ e_flags :,
265+ e_ehsize :,
266+ e_phentsize :,
267+ e_phnum : 1 ,
268+ e_shentsize :,
269+ e_shnum : 0 ,
270+ e_shstrndx : 0
271+ }
272+ @phdrs = [
273+ {
274+ p_type : 1 ,
275+ p_flags : 5 ,
276+ p_offset :,
277+ p_vaddr :,
278+ p_paddr : 0 ,
279+ p_filesz :,
280+ p_memsz :,
281+ p_align : 4096
282+ }
283+ ]
284+ @shdrs = [ ]
285+
286+ dump ( file )
287+ file . write ( entry )
288+ end
289+ end
290+ end
291+
161292# This is a FileUtils extension that defines several additional commands to be
162293# added to the FileUtils utility functions.
163294module FileUtils
305436# The {SassConfig} module.
306437module SassConfig
307438 module Platform
439+ CPU = case RbConfig ::CONFIG [ 'host_cpu' ] . downcase
440+ when /amd64|x86_64|x64/
441+ 'x86_64'
442+ when /i\d 86|x86|i86pc/
443+ 'x86'
444+ when /arm64|aarch64/
445+ 'aarch64'
446+ when /arm/
447+ 'arm'
448+ when /ppc64le|powerpc64le/
449+ 'powerpc64le'
450+ else
451+ RbConfig ::CONFIG [ 'host_cpu' ]
452+ end
453+
454+ LINUXULATOR = if RbConfig ::CONFIG [ 'host_os' ] . include? ( 'freebsd' )
455+ begin
456+ Rake ::Task [ "true-#{ CPU } " ] . invoke
457+ RbConfig ::CONFIG [ 'host_os' ] = 'linux-gnu' if system ( "./true-#{ CPU } " )
458+ true
459+ rescue NotImplementedError
460+ false
461+ end
462+ else
463+ false
464+ end
465+
308466 OS = case RbConfig ::CONFIG [ 'host_os' ] . downcase
309467 when /darwin/
310468 'darwin'
@@ -322,21 +480,6 @@ module SassConfig
322480 RbConfig ::CONFIG [ 'host_os' ] . downcase
323481 end
324482
325- CPU = case RbConfig ::CONFIG [ 'host_cpu' ] . downcase
326- when /amd64|x86_64|x64/
327- 'x86_64'
328- when /i\d 86|x86|i86pc/
329- 'x86'
330- when /arm64|aarch64/
331- 'aarch64'
332- when /arm/
333- 'arm'
334- when /ppc64le|powerpc64le/
335- 'powerpc64le'
336- else
337- RbConfig ::CONFIG [ 'host_cpu' ]
338- end
339-
340483 ARCH = "#{ CPU } -#{ OS } " . freeze
341484 end
342485
@@ -518,4 +661,8 @@ module SassConfig
518661 platform
519662 end
520663 end
664+
665+ def linuxulator?
666+ Platform ::LINUXULATOR
667+ end
521668end
0 commit comments