Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
cfe8b0c8
Unverified
Commit
cfe8b0c8
authored
Aug 29, 2020
by
Rory OConnell
Committed by
Yukihiro "Matz" Matsumoto
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add methods for asking about compiler features
parent
026726dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
lib/mruby/build/command.rb
lib/mruby/build/command.rb
+66
-0
No files found.
lib/mruby/build/command.rb
View file @
cfe8b0c8
require
'forwardable'
require
'forwardable'
require
'tempfile'
module
MRuby
module
MRuby
class
Command
class
Command
...
@@ -126,6 +127,31 @@ module MRuby
...
@@ -126,6 +127,31 @@ module MRuby
end
end
end
end
def
compiles?
(
source_text
)
infile
=
Tempfile
.
new
[
''
,
'.c'
]
infile
.
write
source_text
infile
.
close
cwd
=
Dir
.
pwd
is_success
=
false
# Change to a tmp dir when compiling so we don't litter compiler artifacts
Dir
.
mktmpdir
do
|
tmpdir
|
Dir
.
chdir
tmpdir
sh
(
command
,
infile
.
path
,
verbose:
false
)
{
|
retval
,
_
|
is_success
=
retval
}
end
infile
.
delete
Dir
.
chdir
cwd
return
is_success
end
def
has_header?
(
header_name
)
compiles?
test_code_template
header:
header_name
end
def
has_function?
(
function_name
,
with_header:
nil
)
compiles?
test_code_template
function:
function_name
,
header:
with_header
end
private
private
#
#
...
@@ -165,6 +191,46 @@ module MRuby
...
@@ -165,6 +191,46 @@ module MRuby
end
.
flatten
.
uniq
end
.
flatten
.
uniq
deps
<<
MRUBY_CONFIG
deps
<<
MRUBY_CONFIG
end
end
def
test_code_template
(
function:
nil
,
header:
nil
)
preamble
=
''
body
=
''
if
header
preamble
+=
<<-
TEMPLATE
#if defined __has_include
#if !__has_include("
#{
header
}
")
#error "Header
#{
header
}
not found"
#endif
#endif
#include <
#{
header
}
>
TEMPLATE
end
if
function
preamble
+=
<<-
TEMPLATE
#if defined __stub_
#{
function
}
|| defined __stub___
#{
function
}
#{
function
}
unavailable
#endif
TEMPLATE
# This is how autoconf works when using a function prototype.
body
+=
<<-
TEMPLATE
void *a = (void*) &
#{
function
}
;
long long b = (long long) a;
return (int) b;
TEMPLATE
else
body
=
'return 0;'
end
<<-
TEMPLATE
#{
preamble
}
int main(void) {{
#{
body
}
}}
TEMPLATE
end
end
end
class
Command::Linker
<
Command
class
Command::Linker
<
Command
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment