Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix twili and libstd #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

20 changes: 0 additions & 20 deletions Xargo.toml

This file was deleted.

135 changes: 1 addition & 134 deletions bindgen/libnx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,137 +3,4 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

// Not direcly including switch.h since new CRC crypto dependencies break bindgen, so skipping CRC header

#include <switch/types.h>
#include <switch/result.h>

#include <switch/nro.h>
#include <switch/nacp.h>

#include <switch/arm/tls.h>
#include <switch/arm/cache.h>
#include <switch/arm/atomics.h>
#include <switch/arm/counter.h>

#include <switch/kernel/svc.h>
#include <switch/kernel/wait.h>
#include <switch/kernel/tmem.h>
#include <switch/kernel/shmem.h>
#include <switch/kernel/mutex.h>
#include <switch/kernel/event.h>
#include <switch/kernel/uevent.h>
#include <switch/kernel/utimer.h>
#include <switch/kernel/rwlock.h>
#include <switch/kernel/condvar.h>
#include <switch/kernel/thread.h>
#include <switch/kernel/semaphore.h>
#include <switch/kernel/virtmem.h>
#include <switch/kernel/detect.h>
#include <switch/kernel/random.h>
#include <switch/kernel/jit.h>
#include <switch/kernel/ipc.h>
#include <switch/kernel/barrier.h>

#include <switch/services/sm.h>
#include <switch/services/smm.h>
#include <switch/services/fs.h>
#include <switch/services/fsldr.h>
#include <switch/services/fspr.h>
#include <switch/services/acc.h>
#include <switch/services/apm.h>
#include <switch/services/applet.h>
#include <switch/services/audin.h>
#include <switch/services/audout.h>
#include <switch/services/audren.h>
#include <switch/services/auddev.h>
#include <switch/services/hwopus.h>
#include <switch/services/csrng.h>
#include <switch/services/lbl.h>
#include <switch/services/i2c.h>
#include <switch/services/gpio.h>
#include <switch/services/bpc.h>
#include <switch/services/pcv.h>
#include <switch/services/psm.h>
#include <switch/services/spsm.h>

#include <switch/services/fatal.h>
#include <switch/services/time.h>
#include <switch/services/usb.h>
#include <switch/services/usbds.h>
#include <switch/services/usbhs.h>
#include <switch/services/hid.h>
#include <switch/services/hidsys.h>
#include <switch/services/irs.h>
#include <switch/services/pl.h>
#include <switch/services/vi.h>
#include <switch/services/nv.h>
#include <switch/services/nifm.h>
#include <switch/services/ns.h>
#include <switch/services/ldr.h>
#include <switch/services/ro.h>
#include <switch/services/pm.h>
#include <switch/services/set.h>
#include <switch/services/lr.h>
#include <switch/services/spl.h>
#include <switch/services/ncm.h>
#include <switch/services/psc.h>
#include <switch/services/caps.h>
#include <switch/services/capssc.h>
#include <switch/services/capssu.h>
#include <switch/services/nfc.h>
#include <switch/services/wlaninf.h>
#include <switch/services/pctl.h>

#include <switch/display/binder.h>
#include <switch/display/parcel.h>
#include <switch/display/buffer_producer.h>
#include <switch/display/native_window.h>
#include <switch/display/framebuffer.h>

#include <switch/nvidia/ioctl.h>
#include <switch/nvidia/graphic_buffer.h>
#include <switch/nvidia/fence.h>
#include <switch/nvidia/map.h>
#include <switch/nvidia/address_space.h>
#include <switch/nvidia/channel.h>
#include <switch/nvidia/gpu.h>
#include <switch/nvidia/gpu_channel.h>

#include <switch/audio/driver.h>

#include <switch/applets/libapplet.h>
#include <switch/applets/pctlauth.h>
#include <switch/applets/error.h>
#include <switch/applets/swkbd.h>
#include <switch/applets/web.h>

#include <switch/runtime/env.h>
#include <switch/runtime/hosversion.h>
#include <switch/runtime/nxlink.h>

#include <switch/runtime/util/utf.h>

#include <switch/runtime/devices/console.h>
#include <switch/runtime/devices/usb_comms.h>
#include <switch/runtime/devices/fs_dev.h>
#include <switch/runtime/devices/romfs_dev.h>
#include <switch/runtime/devices/socket.h>

#include <switch/crypto/aes.h>
#include <switch/crypto/aes_cbc.h>
#include <switch/crypto/aes_ctr.h>
#include <switch/crypto/aes_xts.h>
#include <switch/crypto/cmac.h>

#include <switch/crypto/sha256.h>
#include <switch/crypto/sha1.h>
#include <switch/crypto/hmac.h>

#ifdef __cplusplus
}
#endif
#include <switch.h>
1,753 changes: 1,558 additions & 195 deletions bindgen/libnx.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion bindgen/twili.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
THIS SOFTWARE.
*/

#include<switch/services/sm.h>
#include <switch.h>

#ifdef __cplusplus
extern "C" {
#endif

Result twiliWriteNamedPipe(Service *pipe, const char *ptr, size_t len);
Result twiliCreateNamedOutputPipe(Service *srv_out, const char* name, size_t len);
Result twiliInitialize(void);
Expand Down
88 changes: 37 additions & 51 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,39 @@ cfg_if! {
#[derive(Debug)]
struct CustomCallbacks;

impl ParseCallbacks for CustomCallbacks
{
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior
{
impl ParseCallbacks for CustomCallbacks {
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior {
MacroParsingBehavior::Default
}

fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind>
{
if _name.starts_with("POLL") && _value < i16::max_value() as i64 && _value > i16::min_value() as i64
{
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind> {
if _name.starts_with("POLL") && _value < i16::max_value() as i64 && _value > i16::min_value() as i64 {
Some(IntKind::I16)
}
else if _name.starts_with("DT_") && _value > 0 && _value < u8::max_value() as i64
{
else if _name.starts_with("DT_") && _value > 0 && _value < u8::max_value() as i64 {
Some(IntKind::U8)
}
else if _name.starts_with("S_IF") && _value > 0 && _value < u32::max_value() as i64
{
else if _name.starts_with("S_IF") && _value > 0 && _value < u32::max_value() as i64 {
Some(IntKind::U32)
}
else if _value < i32::max_value() as i64 && _value > i32::min_value() as i64
{
else if _value < i32::max_value() as i64 && _value > i32::min_value() as i64 {
Some(IntKind::I32)
}
else
{
else {
None
}
}

fn enum_variant_behavior(&self, _enum_name: Option<&str>, _original_variant_name: &str, _variant_value: EnumVariantValue,) -> Option<EnumVariantCustomBehavior>
{
fn enum_variant_behavior(&self, _enum_name: Option<&str>, _original_variant_name: &str, _variant_value: EnumVariantValue,) -> Option<EnumVariantCustomBehavior> {
None
}

fn enum_variant_name(&self, _enum_name: Option<&str>, _original_variant_name: &str, _variant_value: EnumVariantValue,) -> Option<String>
{
fn enum_variant_name(&self, _enum_name: Option<&str>, _original_variant_name: &str, _variant_value: EnumVariantValue,) -> Option<String> {
None
}
}

pub fn regen_bindings(input: &str, output: &str, whitelist: Option<Vec<String>>) -> Result<bindgen::Bindings, std::io::Error>
{
pub fn regen_bindings(input: &str, output: &str, whitelist: Option<Vec<String>>) -> Result<bindgen::Bindings, std::io::Error> {
// we don't care if deletion succeeds, as long as the file is gone
let _ = std::fs::remove_file(output);
assert!(!std::path::Path::new(output).exists());
Expand Down Expand Up @@ -86,36 +75,31 @@ cfg_if! {
builder.generate().map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Could not create file!")).and_then(|bnd| {
let mut file = OpenOptions::new().write(true).create(true).open(output)?;
file.write_all(br#"mod ctypes {
pub type c_void = core::ffi::c_void;
pub type c_char = u8;
pub type c_int = i32;
pub type c_long = i64;
pub type c_longlong = i64;
pub type c_schar = i8;
pub type c_short = i16;
pub type c_uchar = u8;
pub type c_uint = u32;
pub type c_ulong = u64;
pub type c_ulonglong = u64;
pub type c_ushort = u16;
pub type size_t = u64;
pub type ssize_t = i64;
pub type c_float = f32;
pub type c_double = f64;
}"#)?;
pub type c_void = core::ffi::c_void;
pub type c_char = u8;
pub type c_int = i32;
pub type c_long = i64;
pub type c_longlong = i64;
pub type c_schar = i8;
pub type c_short = i16;
pub type c_uchar = u8;
pub type c_uint = u32;
pub type c_ulong = u64;
pub type c_ulonglong = u64;
pub type c_ushort = u16;
pub type size_t = u64;
pub type ssize_t = i64;
pub type c_float = f32;
pub type c_double = f64;
}"#)?;
bnd.write(Box::new(file)).map(|_| bnd)
})
}

pub fn bindgen()
{
// Where the Rust code will be generated to
pub fn bindgen() {
let gen_path = "bindgen/libnx.rs";

// Input header
let header_wrapper = "bindgen/libnx.h";

// Use bindgen crate to process libnx headers
regen_bindings(header_wrapper, gen_path, None).expect("Error generating libnx bindings!");
}
} else {
Expand All @@ -135,20 +119,21 @@ cfg_if! {
build.include("/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/8.3.0/include/");
build.include("/opt/devkitpro/devkitA64/aarch64-none-elf/include");
build.include("/opt/devkitpro/libnx/include");
build.include("twili-libnx/include");
build.file("twili-libnx/src/twili.c");
build.target("aarch64-none-elf");
build.include("twili/include");
build.file("twili/src/twili.c");
build.compiler("/opt/devkitpro/devkitA64/bin/aarch64-none-elf-gcc");
build.compile("libtwili.a");
}
} else {
pub fn compile_twili() {}
pub fn compile_twili() {
}
}
}

cfg_if! {
if #[cfg(all(feature = "twili", feature = "bindgen"))] {
pub fn twili_bindgen() {
regen_bindings("bindgen/twili.h", "bindgen/twili.rs",
regen_bindings("bindgen/twili.h", "bindgen/twili.rs",
Some(vec!["twiliWriteNamedPipe".to_string(), "twiliCreateNamedOutputPipe".to_string(), "twiliCreateNamedOutputPipe".to_string(), "twiliInitialize".to_string(), "twiliExit".to_string()])
).expect("Error generating twili bindings!");
}
Expand All @@ -159,7 +144,8 @@ cfg_if! {
}
}
} else {
pub fn twili_bindgen() {}
pub fn twili_bindgen() {
}
}
}

Expand Down
1 change: 0 additions & 1 deletion twili-libnx
Submodule twili-libnx deleted from 8cfcc8
13 changes: 13 additions & 0 deletions twili/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2019 misson20000

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
31 changes: 31 additions & 0 deletions twili/include/twili.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2019 misson20000

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
*/

#pragma once

#include <switch.h>

#ifdef __cplusplus
extern "C" {
#endif
Result twiliWriteNamedPipe(Service *pipe, const char *ptr, size_t len);
Result twiliCreateNamedOutputPipe(Service *srv_out, const char* name, size_t len);
Result twiliInitialize(void);
void twiliExit(void);

#ifdef __cplusplus
}
#endif
Loading