From 9601777893a7a4b3b88c70916b7995e83db2ba57 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 9 Jun 2014 22:43:42 +0900 Subject: Add ".s" to source extensions. It uses ".s" as the source for assembler on some toolchains including GCC. --- tasks/mrbgem_spec.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake index 0c4dc85c0..a367e0dbb 100644 --- a/tasks/mrbgem_spec.rake +++ b/tasks/mrbgem_spec.rake @@ -58,13 +58,13 @@ module MRuby @linker = LinkerConfig.new([], [], [], []) @rbfiles = Dir.glob("#{dir}/mrblib/*.rb").sort - @objs = Dir.glob("#{dir}/src/*.{c,cpp,cxx,cc,m,asm,S}").map do |f| + @objs = Dir.glob("#{dir}/src/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X")) end @objs << objfile("#{build_dir}/gem_init") @test_rbfiles = Dir.glob("#{dir}/test/*.rb") - @test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,S}").map do |f| + @test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X")) end @test_preload = nil # 'test/assert.rb' -- cgit v1.2.3 From 2c144425d911fe90670313bff950fe0a0b18cf56 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 9 Jun 2014 22:55:02 +0900 Subject: Find c++ files in tools/. Some tools may be written in C++. --- tasks/mruby_build_gem.rake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks/mruby_build_gem.rake b/tasks/mruby_build_gem.rake index e58dc5c71..5d2dc030c 100644 --- a/tasks/mruby_build_gem.rake +++ b/tasks/mruby_build_gem.rake @@ -35,8 +35,9 @@ module MRuby Gem.current.build_config_initializer = block gems << Gem.current - cxx_srcs = Dir.glob("#{Gem.current.dir}/src/*.{cpp,cxx,cc}") - cxx_srcs += Dir.glob("#{Gem.current.dir}/test/*.{cpp,cxx,cc}") + cxx_srcs = ['src', 'test', 'tools'].map do |subdir| + Dir.glob("#{Gem.current.dir}/#{subdir}/*.{cpp,cxx,cc}") + end.flatten enable_cxx_abi unless cxx_srcs.empty? Gem.current -- cgit v1.2.3 From c6d589e04900c0b90428d78931b7dfa3b4827b62 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 9 Jun 2014 23:08:13 +0900 Subject: Do not export include/ dirs in mrbgems to core build. In the current behavior, include/ dirs in mrbgems are set to core's compiler.include_paths. And they are never set to mrbgem's include_paths. It may cause some dangerous issues because it can change mruby core's macros by mrbgems. After this fix, include/ in a gem is used in the gem itself only. --- tasks/mrbgem_spec.rake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake index 0c4dc85c0..5e2f3fe22 100644 --- a/tasks/mrbgem_spec.rake +++ b/tasks/mrbgem_spec.rake @@ -49,9 +49,6 @@ module MRuby def setup MRuby::Gem.current = self - @build.compilers.each do |compiler| - compiler.include_paths << "#{dir}/include" - end if File.directory? "#{dir}/include" MRuby::Build::COMMANDS.each do |command| instance_variable_set("@#{command}", @build.send(command).clone) end @@ -88,6 +85,7 @@ module MRuby compilers.each do |compiler| compiler.define_rules build_dir, "#{dir}" compiler.defines << %Q[MRBGEM_#{funcname.upcase}_VERSION=#{version}] + compiler.include_paths << "#{dir}/include" if File.directory? "#{dir}/include" end define_gem_init_builder -- cgit v1.2.3 From 7b6150ab904eefc369710f3419bb96bac73ce31f Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 9 Jun 2014 23:39:43 +0900 Subject: Add include_paths in dependency gems. --- tasks/mrbgem_spec.rake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake index 09e000a4a..c8868fe9c 100644 --- a/tasks/mrbgem_spec.rake +++ b/tasks/mrbgem_spec.rake @@ -34,6 +34,8 @@ module MRuby attr_accessor :requirements attr_reader :dependencies + attr_accessor :export_include_paths + attr_block MRuby::Build::COMMANDS def initialize(name, &block) @@ -71,6 +73,8 @@ module MRuby @requirements = [] @dependencies = [] + @export_include_paths = [] + @export_include_paths << "#{dir}/include" if File.directory? "#{dir}/include" instance_eval(&@initializer) @@ -336,6 +340,25 @@ module MRuby rescue TSort::Cyclic => e fail "Circular mrbgem dependency found: #{e.message}" end + + each do |g| + import_include_paths(g) + end + end + + def import_include_paths(g) + gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res } + g.dependencies.each do |dep| + dep_g = gem_table[dep[:gem]] + # We can do recursive call safely + # as circular dependency has already detected in the caller. + import_include_paths(dep_g) + + g.compilers.each do |compiler| + compiler.include_paths += dep_g.export_include_paths + g.export_include_paths += dep_g.export_include_paths + end + end end end # List end # Gem -- cgit v1.2.3 From 4e5315ff4110c467e81f273ff0af95c98b0c5bc7 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 10 Jun 2014 11:02:45 +0900 Subject: Add more info about "include_paths and GEM dependency". --- doc/mrbgems/README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 7ac225730..571c00450 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -75,6 +75,8 @@ contains every gem found in the *mrbgems* directory. The maximal GEM structure looks like this: +- GEM_NAME <- Name of GEM + | + +- include/ <- Header for Ruby extension (will exported) | +- mrblib/ <- Source for Ruby extension | @@ -87,10 +89,10 @@ The maximal GEM structure looks like this: +- README.md <- Readme for GEM The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* -contains C files to extend mruby. The folder *test* contains C and pure Ruby files -for testing purposes which will be used by `mrbtest`. *mrbgem.rake* contains -the specification to compile C and Ruby files. *README.md* is a short description -of your GEM. +contains C/C++ files to extend mruby. The folder *include* contains C/C++ header +files. The folder *test* contains C/C++ and pure Ruby files for testing purposes +which will be used by `mrbtest`. *mrbgem.rake* contains the specification +to compile C and Ruby files. *README.md* is a short description of your GEM. ## Build process @@ -173,6 +175,19 @@ the following options additionally inside of your GEM specification: * `spec.test_objs` (Object test files for integration into mrbtest) * `spec.test_preload` (Initialization files for mrbtest) +### include_paths and depencency + +Your GEM can export include paths to another GEMs that depends on your GEM. +By default, `/...absolute path.../{GEM_NAME}/include` will be exported. +So it is recommended not to put GEM's local header files on include/. + +These exports are retroactive. +For example: when B depends to C and A depends to B, A will get include paths exported by C. + +Exported include_paths are automatically appended to GEM local include_paths by Minirake. +You can use `spec.export_include_paths` accessor if you want more complex build. + + ## C Extension mruby can be extended with C. This is possible by using the C API to -- cgit v1.2.3