This repository was archived by the owner on Nov 26, 2020. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1
 
Generate Cargo build files and make the crate template more accepting #1
          
     Open
      
      
            jadahl
  wants to merge
  7
  commits into
  gi-rust:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
jadahl:wip/dyn-template+cargo
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      95764bd
              
                Don't unwrap pointer ctype for arrays
              
              
                jadahl cab3a6b
              
                Add option for generating Cargo build file
              
              
                jadahl 8cc1c98
              
                Ignore aliases and declarations containinig unmappable types
              
              
                jadahl 15cfd14
              
                Make unmappable structs and unions opaque
              
              
                jadahl f1efa28
              
                Add options to include or exclude crates to be referenced
              
              
                jadahl 40d225e
              
                Put Cargo.toml generation in its own file
              
              
                jadahl 2dfb2ff
              
                Generate build.rs together with the sys crate Cargo.toml
              
              
                jadahl File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # coding: UTF-8 | ||
| # grust-gen - Rust binding generator for GObject introspection | ||
| # | ||
| # Copyright (C) 2016 Jonas Ådahl <[email protected]> | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 2.1 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| # 02110-1301 USA | ||
| 
     | 
||
| import os | ||
| from ..mapping import sys_crate_name | ||
| from ..output import FileOutput | ||
| 
     | 
||
| class SysCargoWriter(object): | ||
| """Generator for -sys Cargo build files.""" | ||
| 
     | 
||
| def __init__(self, mapper, transformer, tmpl_lookup, path): | ||
| self._mapper = mapper | ||
| self._transformer = transformer | ||
| self._cargo_template = tmpl_lookup.get_template('cargo/cargo.tmpl') | ||
| self._build_rs_template = tmpl_lookup.get_template('cargo/build.rs.tmpl') | ||
| self._cargo_file = os.path.join(path, 'Cargo.toml') | ||
| self._build_rs_file = os.path.join(path, 'build.rs') | ||
| 
     | 
||
| def _write_cargo(self, output): | ||
| pkgname = sys_crate_name(self._transformer.namespace) | ||
| version = self._transformer.namespace.version | ||
| result = self._cargo_template.render_unicode(mapper=self._mapper, | ||
| pkgname=pkgname, | ||
| version=version) | ||
| output.write(result) | ||
| 
     | 
||
| def _write_build_rs(self, output): | ||
| pkgconfig_packages = self._transformer.namespace.exported_packages | ||
| result = self._build_rs_template.render_unicode(packages=pkgconfig_packages) | ||
| output.write(result) | ||
| 
     | 
||
| def write(self): | ||
| cargo_output = FileOutput(self._cargo_file, encoding='utf-8') | ||
| with cargo_output as output: | ||
| try: | ||
| self._write_cargo(output) | ||
| except Exception: | ||
| raise SystemExit(1) | ||
| 
     | 
||
| build_rs_output = FileOutput(self._build_rs_file, encoding='utf-8') | ||
| with build_rs_output as output: | ||
| try: | ||
| self._write_build_rs(output) | ||
| except Exception: | ||
| raise SystemExit(1) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| extern crate pkg_config; | ||
| 
     | 
||
| const PACKAGES: &'static [ &'static str ] = &[ | ||
| % for package in packages: | ||
| "${package}", | ||
| % endfor | ||
| ]; | ||
| 
     | 
||
| fn main() { | ||
| for package in PACKAGES { | ||
| pkg_config::probe_library(package).unwrap(); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| [package] | ||
| name = "${pkgname}" | ||
| version = "0.0.1" | ||
| build = "build.rs" | ||
| 
     | 
||
| [lib] | ||
| path = "lib.rs" | ||
| 
     | 
||
| [build-dependencies] | ||
| pkg-config = "0.3.7" | ||
| 
     | 
||
| [dependencies.libc] | ||
| git = "https://github.com/rust-lang/libc.git" | ||
| 
     | 
||
| [dependencies.grust] | ||
| git = "https://github.com/gi-rust/grust.git" | ||
| 
     | 
||
| [dependencies.gtypes] | ||
| git = "https://github.com/gi-rust/gtypes.git" | ||
| 
     | 
||
| % for xc in mapper.extern_crates(): | ||
| % if xc.name is not 'libc' and not mapper.is_excluded(xc): | ||
| [dependencies.${xc.name}] | ||
| path = "../${xc.name}" | ||
| % endif | ||
| % endfor | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might work for objects and some boxed types, but I wouldn't like to get unusable types for copyable values. What I did in the few crate-specific templates I created in repo
gi-rust/cratesis suppress the unmappable structures and place manual representations in the crate template. With support for unions available in stable Rust, there will be less need for these overrides.Bit fields could be automated too, if there is a equivalent
#[repr(C)]guaranteed by the C standard.