Add generator
This commit is contained in:
		
							parent
							
								
									62eb0d6104
								
							
						
					
					
						commit
						bec996d6ae
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
*.exe
 | 
			
		||||
*.pdb
 | 
			
		||||
							
								
								
									
										45
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,45 @@
 | 
			
		|||
This software is available as a choice of the following licenses. Choose
 | 
			
		||||
whichever you prefer.
 | 
			
		||||
 | 
			
		||||
===============================================================================
 | 
			
		||||
ALTERNATIVE 1 - Public Domain (www.unlicense.org)
 | 
			
		||||
===============================================================================
 | 
			
		||||
This is free and unencumbered software released into the public domain.
 | 
			
		||||
 | 
			
		||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
 | 
			
		||||
software, either in source code form or as a compiled binary, for any purpose,
 | 
			
		||||
commercial or non-commercial, and by any means.
 | 
			
		||||
 | 
			
		||||
In jurisdictions that recognize copyright laws, the author or authors of this
 | 
			
		||||
software dedicate any and all copyright interest in the software to the public
 | 
			
		||||
domain. We make this dedication for the benefit of the public at large and to
 | 
			
		||||
the detriment of our heirs and successors. We intend this dedication to be an
 | 
			
		||||
overt act of relinquishment in perpetuity of all present and future rights to
 | 
			
		||||
this software under copyright law.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 | 
			
		||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 | 
			
		||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
For more information, please refer to <http://unlicense.org/>
 | 
			
		||||
 | 
			
		||||
===============================================================================
 | 
			
		||||
ALTERNATIVE 2 - MIT No Attribution
 | 
			
		||||
===============================================================================
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
 | 
			
		||||
this software and associated documentation files (the "Software"), to deal in
 | 
			
		||||
the Software without restriction, including without limitation the rights to
 | 
			
		||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 | 
			
		||||
of the Software, and to permit persons to whom the Software is furnished to do
 | 
			
		||||
so.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
SOFTWARE.
 | 
			
		||||
							
								
								
									
										17
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
# dr_libs.jai
 | 
			
		||||
 | 
			
		||||
Jai bindings for [dr_libs](https://github.com/mackron/dr_libs)
 | 
			
		||||
 | 
			
		||||
## Initial setup
 | 
			
		||||
 | 
			
		||||
If you want to build the lib then you'll need the source code. You can do this with: `git submodule update --init --recursive`.
 | 
			
		||||
In the future if you need to pull in the source submodule again (e.g. the folder got deleted), then run: `git submodule update --recursive`
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
Simply import the module. If you're using a static library version then you're set. If you generated a DLL (and new bindings to load it) then you need to copy the DLL from the windows/ folder to the working directory of your exe.
 | 
			
		||||
 | 
			
		||||
## TODO
 | 
			
		||||
 | 
			
		||||
* Add support for other platforms.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										133
									
								
								generate.jai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								generate.jai
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,133 @@
 | 
			
		|||
#!/usr/bin/env jai
 | 
			
		||||
 | 
			
		||||
libs_to_include: Libs = Libs.DR_WAV | Libs.DR_FLAC | Libs.DR_MP3; // @consider making this a metaprogram/command line arg?
 | 
			
		||||
 | 
			
		||||
Libs :: enum_flags {
 | 
			
		||||
    DR_WAV;
 | 
			
		||||
    DR_FLAC;
 | 
			
		||||
    DR_MP3;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AT_COMPILE_TIME :: true;
 | 
			
		||||
 | 
			
		||||
COMPILE       :: true;  // Enable to compile the dr_libs library from source before generating bindings.
 | 
			
		||||
COMPILE_DEBUG :: false; // Compile a debug or release version of dr_libs
 | 
			
		||||
 | 
			
		||||
MAKE_STATIC_LIB  :: true;
 | 
			
		||||
MAKE_DYNAMIC_LIB :: false;
 | 
			
		||||
 | 
			
		||||
#assert (MAKE_STATIC_LIB || MAKE_DYNAMIC_LIB) && !(MAKE_STATIC_LIB && MAKE_DYNAMIC_LIB);
 | 
			
		||||
 | 
			
		||||
SOURCE_PATH :: "source";
 | 
			
		||||
 | 
			
		||||
#if AT_COMPILE_TIME {
 | 
			
		||||
    #run {
 | 
			
		||||
        set_build_options_dc(.{do_output=false});
 | 
			
		||||
        if !generate_bindings() {
 | 
			
		||||
            compiler_set_workspace_status(.FAILED);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
else {
 | 
			
		||||
    #import "System";
 | 
			
		||||
 | 
			
		||||
    main :: () {
 | 
			
		||||
        set_working_directory(path_strip_filename(get_path_of_running_executable()));
 | 
			
		||||
        if !generate_bindings() {
 | 
			
		||||
            exit(1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
generate_bindings :: () -> bool {
 | 
			
		||||
    if libs_to_include == 0 {
 | 
			
		||||
        log_error("You need to specify at least one library for binding generation!\n");
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Prepare the source for our needs.
 | 
			
		||||
    {
 | 
			
		||||
        copy_file(tprint("%/dr_wav.h",  SOURCE_PATH), tprint("%/dr_wav.c",  SOURCE_PATH));
 | 
			
		||||
        copy_file(tprint("%/dr_flac.h", SOURCE_PATH), tprint("%/dr_flac.c", SOURCE_PATH));
 | 
			
		||||
        copy_file(tprint("%/dr_mp3.h",  SOURCE_PATH), tprint("%/dr_mp3.c",  SOURCE_PATH));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    src_files: [..] string;
 | 
			
		||||
    extra: [..] string;
 | 
			
		||||
 | 
			
		||||
    libs_info := type_info(Libs);
 | 
			
		||||
    for libs_info.values {
 | 
			
		||||
        if libs_to_include & cast(Libs)it {
 | 
			
		||||
            name := libs_info.names[it_index];
 | 
			
		||||
            array_add(*src_files, tprint("%/%.c", SOURCE_PATH, to_lower_copy(name)));
 | 
			
		||||
            array_add(*extra, tprint("/D%_IMPLEMENTATION", name));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #if COMPILE {
 | 
			
		||||
        #import "BuildCpp";
 | 
			
		||||
 | 
			
		||||
        success := false;
 | 
			
		||||
 | 
			
		||||
        #if OS == .WINDOWS {
 | 
			
		||||
            make_directory_if_it_does_not_exist("windows");
 | 
			
		||||
 | 
			
		||||
            #if MAKE_DYNAMIC_LIB {
 | 
			
		||||
                success = build_cpp_dynamic_lib("windows/dr_libs", ..src_files, extra = extra, debug=COMPILE_DEBUG);
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                success = build_cpp_static_lib("windows/dr_libs", ..src_files, extra = extra, debug=COMPILE_DEBUG);
 | 
			
		||||
                if success {
 | 
			
		||||
                    // Remove existing DLL otherwise the bindings will have a "#library" directive that loads the DLL. The lib version is "#library,no_dll"
 | 
			
		||||
                    if file_exists("windows/dr_libs.dll") {
 | 
			
		||||
                        deleted := file_delete("windows/dr_libs.dll");
 | 
			
		||||
                        if !deleted {
 | 
			
		||||
                            log_error("Failed to remove existing dr_libs.dll from the windows/ folder.\n\n");
 | 
			
		||||
                            success = false;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            log_error("This OS isn't supported yet.\n");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if !success return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    output_filename: string;
 | 
			
		||||
    opts: Generate_Bindings_Options;
 | 
			
		||||
    {
 | 
			
		||||
        using opts;
 | 
			
		||||
 | 
			
		||||
        #if OS == .WINDOWS {
 | 
			
		||||
            array_add(*libpaths, "windows");
 | 
			
		||||
            output_filename = "windows.jai";
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            log_error("This OS isn't supported yet.\n");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        array_add(*libnames, "dr_libs");
 | 
			
		||||
        array_add(*system_include_paths, GENERATOR_DEFAULT_SYSTEM_INCLUDE_PATH);
 | 
			
		||||
        array_add(*include_paths, SOURCE_PATH);
 | 
			
		||||
 | 
			
		||||
        source_files = src_files;
 | 
			
		||||
 | 
			
		||||
        log_stripped_declarations = false; // Set to true if things aren't working...
 | 
			
		||||
        generate_compile_time_struct_checks = true;
 | 
			
		||||
    }
 | 
			
		||||
    return generate_bindings(opts, output_filename);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#scope_file
 | 
			
		||||
 | 
			
		||||
#import "Basic";
 | 
			
		||||
#import "Bindings_Generator";
 | 
			
		||||
#import "Compiler";
 | 
			
		||||
#import "File";
 | 
			
		||||
#import "File_Utilities";
 | 
			
		||||
#import "String";
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								module.jai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								module.jai
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
#scope_module
 | 
			
		||||
 | 
			
		||||
size_t :: u64;
 | 
			
		||||
 | 
			
		||||
#import "Basic";
 | 
			
		||||
 | 
			
		||||
#if OS == .WINDOWS {
 | 
			
		||||
    #load "windows.jai";
 | 
			
		||||
}
 | 
			
		||||
else {
 | 
			
		||||
    assert(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3103
									
								
								windows.jai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3103
									
								
								windows.jai
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								windows/dr_libs.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								windows/dr_libs.lib
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user